在一个前端页面上,需要通过JavaScript来提交参数,使用JS创建form表单,将参数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)时不能成功提交,经过研究发现,FireFox在提交页面表单时要求页面有完整的标签项,即<html><head><title></title></head><body><form></form</body</html>这样的标签结构。因此,将该段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>标签内append此处创建的form表单,再进行提交就能成功了。

以上就是【用JS提交参数创建form表单在FireFox中遇到的问题】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)

与本文相关的软件

发表我的评论

最新评论

  1. 暂无评论