Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement checkbox selection by javascrip and jquery

Shulou Source: shulou.com Published: 2022-06-03 09:50:15 10月02日 Update

This article is about how javascrip and jquery implement the full selection of checkbox. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Because under asp.net, the server control will automatically generate the ID and name properties. Therefore, it is more troublesome to use javascrip to achieve full selection.

Here is the code:

[javascript]

Functionquanxuan () {

Varobj=document.getElementById ("btnSelectAll")

If (obj.value== "Select all") {

$("input:checkbox") Attr ("checked", true); / / set all to selected

Obj.value= "cancel"

}

Else {

How to realize checkbox full selection by javascrip+jquery

$("input:checkbox") Attr ("checked", false); / / set all to unchecked

Obj.value= "Select all"

}

}

Call code:

[html]

Of course, the author's approach is relatively rough, the author is to select all the checkbox in the document, if you want to select a specific checkbox, such as just the check box in table, you can filter through the selector of jquery. Such as:

[html]

$("table:checkbox")

Thank you for reading! This is the end of the article on "how to select all javascrip and jquery checkbox". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Code content more author article good practical rough practice but can pass properties controls documents articles servers look knowledge automatic generation trouble Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn Microsoft OPPO Reno Huawei