Jquery uses is (": checked") to determine whether multiple selection boxes are selected.

Source: Internet
Author: User

In jquery, you only need to use is (": checked") to determine whether checkbox is selected. Let's take a look at an instance and hope to help you.

Is (": checked") is a very useful jQuery method that can quickly determine whether multiple objects are selected.

The following is an example:

The Code is as follows: Copy code


<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> 1-6-1 </title>
<! -- Introduce jQuery -->
<Script src = ".../scripts/jquery-1.3.1.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
// Wait until the dom element is loaded.
$ (Document). ready (function (){
Var $ cr = $ ("# cr"); // jQuery object
$ Cr. click (function (){
If ($ cr. is (": checked") {// jQuery method judgment
Alert ("thank you for your support! You can continue! ");
}
})
});
</Script>
</Head>
<Body>
<Input type = "checkbox" id = "cr"/> <label for = "cr"> I have read the above rules. </label>
</Body>
</Html>

Attach a all-selected instance

The Code is as follows: Copy code

<Script type = "text/javascript">
$ (Function (){
$ ("# Selectall"). click (function (){
$ ("Input [@ name = 'your user [] ']"). each (function (){
$ (This). attr ("checked", true );
});
});
$ ("# Deselectall"). click (function (){
$ ("Input [@ name = 'your user [] ']"). each (function (){
$ (This). attr ("checked", false );
});
});
});
</Script>
 
<Input type = 'checkbox' id = 'in-shareuser-10 'name = 'your user [] 'value = '10'/> UserA
<Input type = 'checkbox' id = 'in-shareuser-11 'name = 'your user [] 'value = '11'/> UserB
<Input type = 'checkbox' id = 'in-shareuser-12 'name = 'your user [] 'value = '12'/> UserC
 
<Input type = "button" id = "selectall" name = "selectall" value = "select all"/>
<Input type = "button" id = "deselectall" name = "deselectall" value = "cancel all"/>

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.