用JS提交參數(shù)創(chuàng)建form表單在FireFox中遇到的問題
更新時(shí)間:2013年01月16日 16:25:29 作者:
在一個(gè)前端頁(yè)面上,需要通過JavaScript來提交參數(shù),使用JS創(chuàng)建form表單,將參數(shù)append到表單中進(jìn)行提交,接下來將介紹如何操作與實(shí)現(xiàn)
在一個(gè)前端頁(yè)面上,需要通過JavaScript來提交參數(shù),使用JS創(chuàng)建form表單,將參數(shù)append到表單中進(jìn)行提交,代碼如下:
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上都能成功運(yùn)行,但在使用FireFox(17.0.1)時(shí)不能成功提交,經(jīng)過研究發(fā)現(xiàn),F(xiàn)ireFox在提交頁(yè)面表單時(shí)要求頁(yè)面有完整的標(biāo)簽項(xiàng),即<html><head><title></title></head><body><form></form</body</html>這樣的標(biāo)簽結(jié)構(gòu)。因此,將該段JS做了寫小改動(dòng):
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>標(biāo)簽內(nèi)append此處創(chuàng)建的form表單,再進(jìn)行提交就能成功了。
Js代碼:
復(fù)制代碼 代碼如下:
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上都能成功運(yùn)行,但在使用FireFox(17.0.1)時(shí)不能成功提交,經(jīng)過研究發(fā)現(xiàn),F(xiàn)ireFox在提交頁(yè)面表單時(shí)要求頁(yè)面有完整的標(biāo)簽項(xiàng),即<html><head><title></title></head><body><form></form</body</html>這樣的標(biāo)簽結(jié)構(gòu)。因此,將該段JS做了寫小改動(dòng):
Js代碼:
復(fù)制代碼 代碼如下:
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>標(biāo)簽內(nèi)append此處創(chuàng)建的form表單,再進(jìn)行提交就能成功了。
相關(guān)文章
javascript中2個(gè)感嘆號(hào)的用法實(shí)例詳解
這篇文章主要介紹了javascript中2個(gè)感嘆號(hào)的用法,并用大量的實(shí)例講述了!!的常見應(yīng)用情況,是非常實(shí)用的技巧,需要的朋友可以參考下2014-09-09常見的瀏覽器存儲(chǔ)方式(cookie、localStorage、sessionStorage)
今天我們從前端的角度了解一下瀏覽器存儲(chǔ),我們常見且常用的存儲(chǔ)方式主要由兩種:cookie、webStorage(localStorage和sessionStorage)。本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2019-05-05JavaScript將頁(yè)面表格導(dǎo)出為Excel的具體實(shí)現(xiàn)
如何將頁(yè)面表格導(dǎo)出為Excel,這在日常工作中很常見,下面為大家詳細(xì)的介紹下使用JavaScript是如何實(shí)現(xiàn)的2013-12-12