It is necessary for data transmission when front-end and back-end interaction, form form transmission data is a way often used
The following summarizes some recent problems
How do buttons outside the form submit the form form
In the front-end layout, we sometimes need to place the submit button outside the form. How do we submit the specified form at this time? Not much to say, code
Just bind a function to the button outside the form like this so that the function will be executed when it is clicked.
The button is not in the form without specifying submit but still submits a form
This is because the default type of the button is submit. If the above problem occurs, you only need to change the type attribute that is not the submit button to button.
The form front end wants to verify and then submit
For a form form, even if a function is defined to trigger the verification of the form content when the button is clicked, the form submission will still be triggered when the submit button is clicked. At this time, you need to know the onsubmit attribute of the form. This attribute is triggered when the form submission event occurs. You can make the value of this attribute a function so that the form can be validated. Simple, how to verify? Look at the code:
First of all, pay attention to the return after onsubmit. This is very important. If it is not, even if it is directly followed by false, it will not affect the submission of the form. If you want it to not submit, just return a false, so a simple form verification is completed.
Operation that prevents input
The non-input of input here refers to the read-only attribute, but the value of input can be changed in other ways. For example:
Although it cannot be input directly through the keyboard, it can be operated through buttons