The ultimate solution for selecting all checkpoints in javascript
It is easy to select the CheckBox or Radio status on the javascript page. Next we will show you the ultimate solution for using the CheckBox in javascript in asp.net, if you have any need, refer.
In our program development, full selection of CheckBox is often used, usually in some data binding controls such as the Gridview.
The following uses Repeater as an example to add the CheckBox control to the headers and items of Repeater.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<Asp: Repeater ID = "rptGroup" runat = "server"> <HeaderTemplate> <Table width = "100%" cellspacing = "1"> <Tr> & Lt; td width = "3%" align = "center" & gt; <Input type = "checkbox" id = "chkAll" name = "chkAll" value = "checkbox" Onclick = "checkAll ('chall', this);"/> </Td> </Tr> </HeaderTemplate> <ItemTemplate> <Tr> <Td align = "center"> <Input type = "checkbox" name = "chkSelect" value = '<% # Eval ("ID") %>' Onclick = "checkAll ('chall', this);"/> </Td> </Tr> </ItemTemplate> <FooterTemplate> </Table> </FooterTemplate> </Asp: Repeater> |
The following is the js script.
The checkAll method is used to select and cancel all checkboxes.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
Function checkAll (chkAllID, thisObj ){ Var chkAll = document. getElementById (chkAllID ); Var chks = document. getElementsByTagName ("input "); Var chkNo = 0; Var selectNo = 0; For (var I = 0; I <chks. length; I ++ ){ If (chks [I]. type = "checkbox "){ // Select all trigger events If (chkAll = thisObj ){ Chks [I]. checked = thisObj. checked; } // Trigger if not all options are selected Else { If (chks [I]. checked & chks [I]. id! = ChkAllID) SelectNo ++; } If (chks [I]. id! = ChkAllID ){ ChkNo ++; } } } If (chkAll! = ThisObj ){ ChkAll. checked = chkNo = selectNo; } } |
The checkSelectNo function is used to obtain the number of all checkbox selections. This function is useful when used to determine whether a checkbox is selected.
?
1 2 3 4 5 6 7 8 9 10 11 12 |
Function checkSelectNo (chkAllID ){ Var chks = document. getElementsByTagName ("input "); Var selectNo = 0; For (var I = 0; I <chks. length; I ++ ){ If (chks [I]. type = "checkbox "){ If (chks [I]. id! = ChkAllID & chks [I]. checked ){ SelectNo ++; } } } Return selectNo; } |
The above is all the content of this article. I hope you will like it.