简体   繁体   English

当“提交”按钮的名称为“ submit”时,欧芹表单未提交

[英]parsley form not submitting when submit button has name=“submit”

I just discovered that my form isn't submitting when i give the submit element the name="submit" attribute. 我刚刚发现,当我给Submit元素命名为name =“ submit”时,表单没有提交。 When I change the the name to something else, it works perfectly! 当我将名称更改为其他名称时,它可以正常工作!

I am using parsley.remote.min.js * Version 2.0.3 - built Mon Jul 21 2014 11:58:33 我正在使用parsley.remote.min.js *版本2.0.3-建于2014年7月21日星期一11:58:33

Sorry I cannot provide code right now, I just wanted to throw that out there. 抱歉,我现在无法提供代码,我只是想将其丢掉。 Is it possibly I am doing something wrong? 我可能做错了吗?

When you name a form element "submit", you inadvertently override the form's submit method with an input object. 当您将表单元素命名为“ submit”时,会无意中用输入对象覆盖表单的submit方法。 For example, with this: 例如,与此:

<form id="testForm">
    <input type="text" name="testInput" />
</form>

You can now access the input element by name through a property on the form object: 现在,您可以通过表单对象上的属性按名称访问输入元素:

var testInput = document.getElementById('testForm').testInput;

Forms have a submit() method you can call programmatically (which is the same one invoked by clicking a button or input of "submit" type): 表单具有可通过编程方式调用的submit()方法(与单击按钮或“提交”类型的输入所调用的方法相同):

document.getElementById('testForm').submit();

Perhaps now you can see the problem by naming a form element "submit" -- you're taking away the form's ability to be submitted because submit() no longer exists -- it's been redefined as a property that returns a reference to your submit button. 也许现在您可以通过将表单元素命名为“ submit”来看到问题了-您正在取消表单的提交功能,因为submit()不再存在-它已被重新定义为可返回对您的提交的引用的属性按钮。

More explanation is available here: 此处提供更多说明:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM