用JS提交參數(shù)創(chuàng)建form表單在FireFox中遇到的問題
更新時間:2013年01月16日 16:25:29 作者:
在一個前端頁面上,需要通過JavaScript來提交參數(shù),使用JS創(chuàng)建form表單,將參數(shù)append到表單中進行提交,接下來將介紹如何操作與實現(xiàn)
在一個前端頁面上,需要通過JavaScript來提交參數(shù),使用JS創(chuàng)建form表單,將參數(shù)append到表單中進行提交,代碼如下:
Js代碼:
functionloadConfig(gameUrl,skinId){
vartemp=document.createElement("form");
temp.action="${createLink(controller:'mobileConfig',action:'beforeLaunchConfig')}";
temp.method="POST";
temp.style.visibility="hidden";
varopt=document.createElement("input");
opt.name="gameUrl";
opt.id="gameUrl";
opt.value=gameUrl;
varopt2=document.createElement("input");
opt2.name="skinId";
opt2.id="skinId";
opt2.value=skinId;
temp.appendChild(opt);
temp.appendChild(opt2);
temp.submit();
}
該功能在Chrome及Safari上都能成功運行,但在使用FireFox(17.0.1)時不能成功提交,經(jīng)過研究發(fā)現(xiàn),F(xiàn)ireFox在提交頁面表單時要求頁面有完整的標簽項,即<html><head><title></title></head><body><form></form</body</html>這樣的標簽結(jié)構(gòu)。因此,將該段JS做了寫小改動:
Js代碼:
functionloadConfig(gameUrl,skinId){
varpageDiv=document.getElementById("page");
vartemp=document.createElement("form");
temp.action="${createLink(controller:'mobileConfig',action:'beforeLaunchConfig')}";
temp.method="POST";
temp.style.visibility="hidden";
temp.name="loadConfigPage";
varopt=document.createElement("input");
opt.name="gameUrl";
opt.id="gameUrl";
opt.value=gameUrl;
varopt2=document.createElement("input");
opt2.name="skinId";
opt2.id="skinId";
opt2.value=skinId;
temp.appendChild(opt);
temp.appendChild(opt2);
pageDiv.appendChild(temp);
temp.submit();
}
在<body>標簽內(nèi)append此處創(chuàng)建的form表單,再進行提交就能成功了。
Js代碼:
復制代碼 代碼如下:
functionloadConfig(gameUrl,skinId){
vartemp=document.createElement("form");
temp.action="${createLink(controller:'mobileConfig',action:'beforeLaunchConfig')}";
temp.method="POST";
temp.style.visibility="hidden";
varopt=document.createElement("input");
opt.name="gameUrl";
opt.id="gameUrl";
opt.value=gameUrl;
varopt2=document.createElement("input");
opt2.name="skinId";
opt2.id="skinId";
opt2.value=skinId;
temp.appendChild(opt);
temp.appendChild(opt2);
temp.submit();
}
該功能在Chrome及Safari上都能成功運行,但在使用FireFox(17.0.1)時不能成功提交,經(jīng)過研究發(fā)現(xiàn),F(xiàn)ireFox在提交頁面表單時要求頁面有完整的標簽項,即<html><head><title></title></head><body><form></form</body</html>這樣的標簽結(jié)構(gòu)。因此,將該段JS做了寫小改動:
Js代碼:
復制代碼 代碼如下:
functionloadConfig(gameUrl,skinId){
varpageDiv=document.getElementById("page");
vartemp=document.createElement("form");
temp.action="${createLink(controller:'mobileConfig',action:'beforeLaunchConfig')}";
temp.method="POST";
temp.style.visibility="hidden";
temp.name="loadConfigPage";
varopt=document.createElement("input");
opt.name="gameUrl";
opt.id="gameUrl";
opt.value=gameUrl;
varopt2=document.createElement("input");
opt2.name="skinId";
opt2.id="skinId";
opt2.value=skinId;
temp.appendChild(opt);
temp.appendChild(opt2);
pageDiv.appendChild(temp);
temp.submit();
}
在<body>標簽內(nèi)append此處創(chuàng)建的form表單,再進行提交就能成功了。
相關文章
常見的瀏覽器存儲方式(cookie、localStorage、sessionStorage)
今天我們從前端的角度了解一下瀏覽器存儲,我們常見且常用的存儲方式主要由兩種:cookie、webStorage(localStorage和sessionStorage)。本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友參考下吧2019-05-05JavaScript將頁面表格導出為Excel的具體實現(xiàn)
如何將頁面表格導出為Excel,這在日常工作中很常見,下面為大家詳細的介紹下使用JavaScript是如何實現(xiàn)的2013-12-12