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"/> |