One. in the HTML checkbox, the selected word will have the attribute checked= "checked ".
If a checkbox is selected, alert the CheckBox's property "checked" with the value alert ($ "#xxx". attr ("checked")), which prints "true" instead of " Checked "!
If not selected, the print is "undefined ". That's weird, isn't it? Keep looking down ~
Do not attempt to make such a judgment: if ($ "#xxx". attr ("checked") = = "true ") //This is wrong
because it's wrong to do this, the jquery API manual says that the return value of attr (name) is object. Therefore, it should be if ($ ("#xxx"). attr ("checked") = =true).
Determine the value of $ ("Input[name= ' Weibo_count ')"). attr ("checked"); that's fine.
"http://www.w3.org/1999/xhtml">
"Server">
<script language="JavaScript">
<!--
$("Document"). Ready (function () {
$("#btn1"). Click (function () {
$("[name= ' checkbox ']"). attr ("checked",'true');//Select All
})
$("#btn2"). Click (function () {
$("[name= ' checkbox ']"). Removeattr ("checked");//Cancel Select all
})
$("#btn3"). Click (function () {
$("[name= ' checkbox ']:even"). attr ("checked",'true');//Check all odd
})
$("#btn4"). Click (function () {
$("[name= ' checkbox ']"). each (function () {
if($( This). attr ("checked"))
{
$( This). Removeattr ("checked");
}
Else
{
$( This). attr ("checked",'true');
}
})
})
$("#btn5"). Click (function () {
varChecks ="";
$("input[name= ' checkbox[]"). each (function () {
if($( This). attr ("checked") ==true){
Checks + = $ ( This). Val () +"|";//dynamically spell the value of the selected checkbox with the ' | ' Symbol Separation
}
})
})
// -
</SCRIPT>
</HEAD>
<BODY>
<form name="Form1"Method="Post"action="">
<input type="Button"Id="BTN1"Value="Select All">
<input type="Button"Id="btn2"Value="Cancel Select all">
<input type="Button"Id="Btn3"Value="Check all odd">
<input type="Button"Id="Btn4"Value="Inverse Selection">
<input type="Button"Id="Btn5"Value="get all the values selected">
<br>
<input type="checkbox"Name="checkbox[]"Value="CheckBox1">
CheckBox1
<input type="checkbox"Name="checkbox[]"Value="CheckBox2">
CheckBox2
<input type="checkbox"Name="checkbox[]"Value="Checkbox3">
Checkbox3
<input type="checkbox"Name="checkbox[]"Value="checkbox4">
Checkbox4
</form>
</body>