Implement checkbox select unselect cancel JavaScript small script exception
- 2020-03-30 02:36:44
- OfStack
Today, when implementing the checkbox full selection, anti-selection, cancel JavaScript small script, there is always a click after the page instantly refresh, the selected checkbox is all cancelled, debug for a long time, only to find the original is < Button> The reason why there is a type attribute missing in the label is depressing. I hope that I will make fewer such special 2 mistakes in the future.
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201404/201404101539471.gif? 2014310154050 ">
After reading the w3c's description, I suddenly realized that when the type attribute was not written, the browser processed it as submit by default, and the script for my form to accept processing was still empty, so the phenomenon of "refresh" was generated!
<!-- The following is the wrong way to write it -->
<button name="checkAll" value=" Future generations " class="checkButton" onClick="checkAll(form_favor,status)"> Future generations </button>
<!-- Correct term -->
<button name="checkAll" type="button" value=" Future generations " class="checkButton" onClick="checkAll(form_favor,status)"> Future generations </button>
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201404/201404101539471.gif? 2014310154050 ">
After reading the w3c's description, I suddenly realized that when the type attribute was not written, the browser processed it as submit by default, and the script for my form to accept processing was still empty, so the phenomenon of "refresh" was generated!