Why Form Elements should not be named submit?

后端 未结 3 1642
梦毁少年i
梦毁少年i 2020-12-21 08:23

I figured out through debugging that I should not name any Form Elements name=\"submit\", but even after searching I didn\'t find any good explanation of why?

3条回答
  •  执念已碎
    2020-12-21 08:48

    If you check the Mozilla docs here : https://developer.mozilla.org/en-US/docs/DOM/HTMLFormElement

    You will see that forms have a .submit() method.

    In addition, forms are also populated with the fields within the form.

    (Here is one example: http://www.devbay.com/articles/javascript/accessing-form-elements-array-with-javascript/ I can't find any reference that it should happen, only that it does.)

    So, when you make an element called submit it over-rides the forms built-in submit() method -- and since the element is, well, not a function, you get that error message.

提交回复
热议问题