While this jsfiddle works:
虽然这个jsfiddle工作:
<form method="post" id="myform1">
<input type="submit" value="submit" />
</form>
document.getElementById("myform1").submit();
This jsfiddle does not work:
这个jsfiddle不起作用:
<form method="post" id="myform2">
<input type="submit" id="submit" value="submit" />
</form>
document.getElementById("myform2").submit();
Difference between them submit
button has id
in second code.
它们之间的区别提交按钮在第二个代码中有id。
Why?
为什么?
Note: while working this question, I encountered situation
注意:在处理这个问题时,我遇到了情况
2 个解决方案
#1
1
the difference is the type of the button not the id
区别在于按钮的类型而不是id
first example the type of the input is submit which submits forms. second example the type is button which doesn't submit forms
第一个例子,输入的类型是提交表单的提交。第二个例子,类型是不提交表单的按钮
after OP editted question:
OP编辑后的问题:
see that if you change the id of the submit button to basicly anything other than "submit" it works...
看看如果你将提交按钮的id改为基本上除了“提交”以外的任何东西,它就有效......
#2
1
This is noted on various sites such as this:
这在以下各种网站上都有说明:
http://www.joezimjs.com/javascript/dont-name-inputs-action-submit/
http://www.joezimjs.com/javascript/dont-name-inputs-action-submit/
Having a button with id='submit'
is also a known issue in jquery that hasn't been resolved
有一个id ='submit'的按钮也是jquery中一个尚未解决的已知问题
http://bugs.jquery.com/ticket/1414
http://bugs.jquery.com/ticket/1414
Presumably because the issue is outside of jquery's control and it'd require a hack.
大概是因为这个问题超出了jquery的控制范围而且需要黑客攻击。
I'd be interested to know exactly why.
我很想知道原因。
#1
1
the difference is the type of the button not the id
区别在于按钮的类型而不是id
first example the type of the input is submit which submits forms. second example the type is button which doesn't submit forms
第一个例子,输入的类型是提交表单的提交。第二个例子,类型是不提交表单的按钮
after OP editted question:
OP编辑后的问题:
see that if you change the id of the submit button to basicly anything other than "submit" it works...
看看如果你将提交按钮的id改为基本上除了“提交”以外的任何东西,它就有效......
#2
1
This is noted on various sites such as this:
这在以下各种网站上都有说明:
http://www.joezimjs.com/javascript/dont-name-inputs-action-submit/
http://www.joezimjs.com/javascript/dont-name-inputs-action-submit/
Having a button with id='submit'
is also a known issue in jquery that hasn't been resolved
有一个id ='submit'的按钮也是jquery中一个尚未解决的已知问题
http://bugs.jquery.com/ticket/1414
http://bugs.jquery.com/ticket/1414
Presumably because the issue is outside of jquery's control and it'd require a hack.
大概是因为这个问题超出了jquery的控制范围而且需要黑客攻击。
I'd be interested to know exactly why.
我很想知道原因。