Mozilla form.submit()不工作 [英] Mozilla form.submit() not working
本文介绍了Mozilla form.submit()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码创建一个动态表单,
I am creating a dynamic form using following code,
function createForm() {
var f = document.createElement("form");
f.setAttribute('method',"post");
f.setAttribute('action',"./Upload");
f.setAttribute('name',"initiateForm");
f.acceptCharset="UTF-8";
var name = document.createElement("input");
name.setAttribute('type',"text");
name.setAttribute('name',"projectname");
name.setAttribute('value',"saket");
f.appendChild(name);
f.submit();
}
但在Mozilla中没有任何反应,但代码的工作原理(在铬)。
这个代码是由另一个函数调用的,这个函数是由click on事件调用的。
执行该代码后,我返回false。
But in Mozilla nothing happens but code works as expected ( in chrome). This code is being called by another function which is invoked by button on click event. After executing this code i am returning false.
请帮助我。
提前感谢: - )
Please help me out. Thanks in advance :-)
推荐答案
您需要将新创建的表单附加到文档中,因为它是不在页面加载。
You need to append the new created form to the document, because it was not there on page load.
尝试这样:
function createForm() {
var f = document.createElement("form");
f.setAttribute('method',"post");
f.setAttribute('action',"./Upload");
f.setAttribute('name',"initiateForm");
f.acceptCharset="UTF-8";
var name = document.createElement("input");
name.setAttribute('type',"text");
name.setAttribute('name',"projectname");
name.setAttribute('value',"saket");
f.appendChild(name);
document.body.appendChild(f); // added this
f.submit();
}
这篇关于Mozilla form.submit()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文