JQuery .trigger('submit') breaking

前端 未结 5 1348
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-21 09:48

Im finding that because all the forms that Im working on have a submit button which inlcudes a \'name=\"submit\"\' attribute, that the trigger submit is breaking when I clic

5条回答
  •  感情败类
    2020-12-21 10:28

    It's because you've given your submit button a name of "submit". Because this is already a property of the form object, it messes with the binding of the submit event.

    See this note from the jQuery docs:

    Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures.

    Change the name of your submit button to anything else ("form_submit", for example) and it'll work.

提交回复
热议问题