Javascript code for full checkbox Selection
This article will share with you all the code for implementing checkbox in js. js code is frequently used in web page creation for your reference.
Code:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 |
Function checkall (checkNames ){ Var allBoxs = document. getElementsByName (checkNames ); For (var I = 0; I <allBoxs. length; I ++ ){ If (allBoxs [I]. type = 'checkbox '){ If (allBoxs [I]. checked = false ){ AllBoxs [I]. checked = true; } Else { AllBoxs [I]. checked = false; } } } } |
Usage ①
The Code is as follows:
<A href = "" onclick = "checkall ('goods ')"> select all </a>
Note: 'goods 'is the name of all the checkboxes to be selected.
Method ②
?
| 1 2 3 4 5 6 |
<A href = "" id = "checkAll"> select all </a> <Script> Document. getElementById ('checkall'). onclick = function (){ Checkall ('goods ') }; </Script> |
Note: 'goods 'is the name of all the checkboxes to be selected.
The above two methods are all summarized in this article. I hope you will like them. If there are better methods, please let us know. This article will be updated continuously.