Today, when I was implementing checkbox selection, reverse selection, and canceling JavaScript small scripts, there was always a problem of instant refreshing the page after clicking, and all selected checkboxes were cancelled. I debugged for a long time and found that there was one less written in the <button> tag. The reason for the type attribute is depressed. I hope I will make less of this special 2 mistake in the future. I will record it here.
The code copy is as follows:
<!-- The following is the error writing method->
<button name="checkAll" value="select all" onClick="checkAll(form_favor,status)">select all</button>
The code copy is as follows:
<!-- Correct writing method-->
<button name="checkAll" type="button" value="select all" onClick="checkAll(form_favor,status)">select all</button>
After reading the description of w3c, I immediately understood that without writing the type attribute, the browser defaulted to processing it as submit, and the script that my form was processed was still empty, so the "refresh" was generated. Phenomenon!