Home>Article>Web Front-end> What is the difference between button button and submit button?
This article brings you what is the difference between the button button and the submit button? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
button-normal button, submit-submit button.
Submit is a special case of button and a type of button. It automatically integrates the action of submission. Both submit and button are displayed in the form of buttons. They both look like buttons. The difference is the type attribute. and respond to events.
Some of the usage scenarios mentioned here do not mean that only one type can be used. It just means that it is more convenient to use in this scenario and the programmer's workload is small.
Use the table to compare:
Scenario | button | submit |
---|---|---|
The web page needs to submit information to the server | √ | |
Execute a common event on the web page, such as reset, Clear function. | √ | |
Submit the form | You need to bind events to submit the form data | √ |
√ | cannot be used. The form will be submitted when the event is triggered. | |
But the button does not submit any data by default. Data can be submitted by binding events. | When submit requires a form, the data will be included when submitting. Of course, you can also use submit, but the onclick event must be intercepted. | |
Need to write a lot of data acquisition actions | Recommendation | |
Recommendation: Submit data through button, then if the user disables JS, then the data submission action cannot be activated | Not recommended |
For example, a login module, first verify whether the user name is empty. If it is empty, the page specified by the from form will never be submitted when SUBMIT is clicked. It can only be sent in form! And the value passed in cannot be verified on the page specified by the form.
function check(){ var name = document.getElementById("name").value; if(name == null || name == ''){ alert("用户名不能为空"); return false; } return true; }