您的位置:首页 > 运维架构

form表单post提交 并且提交到一个新的窗口(注意:window.open()形式的窗口)

2013-07-20 16:57 2101 查看
JS代码:

<script type="text/javascript" src="jquery-1.2.6.js" ></script>

<script>

function windowOpen(){

 var toDay = new Date();

 winName = "win"+toDay.getTime();//为了保证提交不会读取本地的缓存

 $("#form1").attr("action","test2.html");//设置form表单提交的URL路径 是 test2.html

//为了表示区分,window.open 打开的是 test3.html

 window.open("test3.html",winName,"status=yes,toolbar=no,menubar=no,location=no");

 $("#form1").attr("target",winName);

 $("#form1").submit();

//代码走到这里之后,将会提交到window.open中的窗口,页面是test2.html

}

</script>

html代码:

<form id="form1" method="post" onsubmit="windowOpen()" >

 <input type="submit" value="提交打开新的页面" />

</form>

知识点:

1、form的target属性,可以设置window的name,为目标窗体 

2、window.open第二个参数,是它的name。 

winName需要设置成一个不重复的id,否则再次点击只会刷新已经打开的window,而不会打开新页面。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息