码迷,mamicode.com
首页 > 其他好文 > 详细

动态生成form表单

时间:2019-09-04 11:44:06      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:临时   top   array   ide   create   scrollbar   doc   新窗口   blank   

 1 function openPostWindow(url, data, name) {
 2     var tempForm = document.createElement("form");
 3     tempForm.id = "tempForm1";
 4     tempForm.method = "post";
 5     tempForm.action = url;
 6     tempForm.target = name; //_blank
 7     for (var i in data) {
 8         //data 为$("#form").serializeArray()的结果
 9         var hideInput = document.createElement("input");
10         hideInput.type = "hidden";
11         hideInput.name = data[i].name;
12         hideInput.value = data[i].value;
13         tempForm.appendChild(hideInput);
14     }
15 
16 
17   //  window.open(‘about:blank‘, name, ‘height=400, width=400, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes‘);
18 
19     //添加临时form
20     document.body.appendChild(tempForm);
21     //必须手动的触发,否则只能看到页面刷新而没有打开新窗口
22     tempForm.submit();
23 
24     //移除临时创建的form
25     document.body.removeChild(tempForm);
26 
27 }

 

动态生成form表单

标签:临时   top   array   ide   create   scrollbar   doc   新窗口   blank   

原文地址:https://www.cnblogs.com/lpp-xjj/p/11457952.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!