动态创建表单模拟提交

        //
        function openPostWindow(orderNo,lineNums,productIds){
            var tempForm = document.createElement("form");
            tempForm.id = "tempForm1";
            tempForm.method = "post"; //表单提交方式
            tempForm.target = "_self";
            tempForm.action = "sys_om_order_copy_to.aspx"; //在此处设置你要跳转的url
            
            //表单要提交的数据
            //1订单号 2 lineNums 3 productIds
            
            var hidInput_orderNO = document.createElement("input");
            hidInput_orderNO.type = "hidden";
            hidInput_orderNO.name = "orderNO";
            hidInput_orderNO.value = orderNo;
            tempForm.appendChild(hidInput_orderNO);
            
            var hidInput_lineNums = document.createElement("input");
            hidInput_lineNums.type = "hidden";
            hidInput_lineNums.name = "lineNums";
            hidInput_lineNums.value = lineNums;
            tempForm.appendChild(hidInput_lineNums);
            
            var hidInput_productIds = document.createElement("input");
            hidInput_productIds.type = "hidden";
            hidInput_productIds.name = "productIds";
            hidInput_productIds.value = productIds;
            tempForm.appendChild(hidInput_productIds);
            
            //attachEvent(IE) addEventListener事件兼容处理
            /*if (window.attachEvent) { 
               tempForm.attachEvent("onsubmit", function () { openWindow(); });
            } else if (window.addEventListener) { 
                tempForm.addEventListener("onsubmit", function () { openWindow(); },false);   
            }*/             
            
            document.body.appendChild(tempForm);
            
            if(document.all){  
                tempForm.fireEvent("onsubmit");  
            }else {   
                var evt = document.createEvent('HTMLEvents');  
                    evt.initEvent('onsubmit',true,true);  
                    tempForm.dispatchEvent(evt );  
              }
            //表单进行提交
            tempForm.submit(); 
            document.body.removeChild(tempForm); //清除
        }
原文地址:https://www.cnblogs.com/yzenet/p/3771695.html