Select none for all JS checkbox and all for jscheckbox

Source: Internet
Author: User

Select none for all JS checkbox and all for jscheckbox

/* JS checkbox: <input type = "checkbox" name = "cbx" value = "<% = Default by yourself %>"/> the following methods have their own advantages and disadvantages, depending on the situation. * /// select all (Method 1: each loop) function checkAll () {$. each ($ ("input [name = cbx]"), function (I) {if ($ (this ). attr ("checked") = false) {$ (this ). attr ("checked", "true") ;}}) ;}// select all (Method 2: function checkAll () {var code_Values = document. all ['cbx']; if (code_Values.length) {for (var I = 0; I <code_Values.length; I ++) {code_Values [I]. checked = true ;}} else {code_Values.checked = true ;}// select all functions (method 3: function checkAll () based on Tag and Type [type in input () {var code_Values = document. getElementsByTagName ("input"); if (code_Values.length) {for (I = 0; I <code_Values.length; I ++) {if (code_Values [I]. type = "checkbox") {code_Values [I]. checked = true ;}} else {if (code_Values.type = "checkbox") {code_Values.checked = true ;}}// no selection (Method 1: each loop) function uncheckAll () {$. each ($ ("input [name = cbx]"), function (I) {if ($ (this ). attr ("checked") = true) {$ (this ). attr ("checked", "false") ;}}) ;}// no selection (Method 2: function uncheckAll () {var code_Values = document. all ['cbx']; if (code_Values.length) {for (var I = 0; I <code_Values.length; I ++) {code_Values [I]. checked = false ;}} else {code_Values.checked = false ;}/// no selection (method 3: function uncheckAll () based on Tag and Type [type in input () {var code_Values = document. getElementsByTagName ("input"); if (code_Values.length) {for (I = 0; I <code_Values.length; I ++) {if (code_Values [I]. type = "checkbox") {code_Values [I]. checked = false ;}} else {if (code_Values.type = "checkbox") {code_Values.checked = false ;}}}

 


Select all and no JS for CheckBox

First, replace the original code with all the following code:
<Table id = "tbList"> <tr> <td>
<Asp: DataList ID = "DataList1" runat = "server" Width = "100%"
>
<HeaderTemplate>
<Table style = "width: 100%; font-size: 10pt;" border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<Td class = "two_out_three_net1" align = "center">
<Input id = "cbxItemAll" runat = "server" name = "chkAll" onclick = "IsorNotAll (this);" type = "checkbox"/>

</Td>
<Td class = "two_out_three_net2" align = "center"> title </td>
<Td class = "two_out_three_net3" align = "center"> clicks </td>
<Td class = "two_out_three_net4" align = "center"> attributes </td>
<Td class = "two_out_three_net5" align = "center"> Status </td>
</Tr>
</Table>
</HeaderTemplate>
<ItemTemplate>
<Table style = "width: 100%; font-size: 10pt; & ...... the remaining full text>

Check whether all or not to select a checkbox

The figure is not clear, but the general principle is as follows:

<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
<Script language = "javascript">
Function selected ()
{
Var allsel = document. getElementsByName ("car ");
For (var I = 0; I <allsel. length; I ++)
{
Allsel [I]. checked =! Allsel [I]. checked;
}
}
</Script>
</Head>

<Body>
<H1> select all/do not select all Select All/cancel <br/>
<Input type = "checkbox" id = "sel" name = "sel" value = "yes" onclick = "selected ()">
<Br/>
<Input type = "checkbox" id = "car" name = "car" value = "two"> aa <br/>
<Input type = "checkbox" id = "car" name = "car" value = "three"> bb <br/>
<Input type = "checkbox" id = "car" name = "car" value = "four"> cc <br/>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.