Home > Article > Web Front-end > Overview of submit() method and onsubmit event application of form elements_Basic knowledge
The form element has a submit method and an onsubmit event handler for monitoring form submission. Form submission can be triggered using the elemForm.submit(); method.
1. An element with name="submit" appears in the form element
In this case elemForm.submit(); will not trigger form submission because the original submit method of the form will will be overwritten (formElem.submit is a reference to the element).
2. elemForm.submit(); will not trigger the onsubmit event of the form
No reason, it is stipulated in the standard.
Somewhat similar to this, the relationship between onfocus, onblur, focus(), and blur() is different. Calling elem.blur() or elem.focus() will trigger onblur and onfocus events.
These provide us with an idea. When designing some UI components, we need to consider whether related events should be triggered when some events are called internally. For example, the Dialog component has an onopen event, and the returned object will also have an open() method. At this time, we must consider whether the open() method needs to trigger the onopen() event.
3. Problems encountered when creating forms dynamically
A frequently used method is as follows. It will be called before the form is submitted, and it will be decided whether it needs to be submitted based on the return value of the validate() function. form.