Jquery version: 1.3.2
CopyCode The Code is as follows: <HTML>
<Head>
<SCRIPT src = "jquery-1.3.2.min.js" type = "text/JavaScript"> </SCRIPT>
</Head>
<Body>
<Input type = "checkbox" name = "chk_list" id = "chk_list_1" value = "1"/> 1 <br/>
<Input type = "checkbox" name = "chk_list" id = "chk_list_2" value = "2"/> 2 <br/>
<Input type = "checkbox" name = "chk_list" id = "chk_list_3" value = "3"/> 3 <br/>
<Input type = "checkbox" name = "chk_list" id = "chk_list_4" value = "4"/> 4 <br/>
<Input type = "checkbox" name = "chk_all" id = "chk_all"/> select all/cancel all
<SCRIPT type = "text/JavaScript">
$ ("# Chk_all"). Click (function (){
$ ("Input [name = 'chk _ list']"). ATTR ("checked", $ (this). ATTR ("checked "));
});
</SCRIPT>
</Body>
</Html>
Jquery. ATTR gets/Sets object attribute values, such:Copy codeThe Code is as follows: $ ("input [name = 'chk _ list']"). ATTR ("checked"); // read the status of all objects whose names are 'chk _ List' (whether or not selected)
$ ("Input [name = 'chk _ list']"). ATTR ("checked", true); // set the checked value of all objects whose names are 'chk _ list' to true.
Another example is:Copy codeThe Code is as follows: $ ("# img_1"). ATTR ("src", "test.jpg"); // set the value of srcto 'test.jpg 'with the ID of img_1'
$ ("# Img_1"). ATTR ("src"); // read the SRC value whose ID is img_1
The following code gets the value of the checkbox selected in the above instance:Copy codeThe Code is as follows: <SCRIPT type = "text/JavaScript">
// Obtain all the checkboxes (sets) whose names are 'chk _ list)
VaR arrchk = $ ("input [name = 'chk _ list] [checked]");
// Obtain the value of each checkbox through Traversal
For (VAR I = 0; I <arrchk. length; I ++)
{
Alert (arrchk [I]. value );
}
</SCRIPT>
I am very grateful to anyone who can write the above traversal process using $. Each.