In the HTML checkbox, the selected word will have attributes checked= "checked".
If a checkbox is selected, the value alert ($ "#xxx" for the CheckBox's property "Checked") is printed "true" instead of "checked" attr ("checked").
If not selected, print out "undefined". That's weird, isn't it? Keep looking!
Don't try to make such a judgment: if ($ "#xxx". attr ("checked") = = "true")
Because it is wrong to do so, the jquery API manual writes that the return value of attr (name) is object.
So, it should be if ($ "#xxx". attr ("checked") ==true)
<script src= "Jquery-1.2.6.pack.js" type= "text/Web Effects" ></script>
<script language= "JavaScript"
$ (document). Ready (function () {
$ ("#checkboxall"). Click (function () {
if ($ (this). attr ("checked")
{
$ (" input[@type = ' checkbox ']. each (function () {
$ (this). attr ("Checked", true);
} );
$ ("#checkshow"). HTML ("12346789");
}
Else
{
$ ("input[@type = ' checkbox ']" each (function () {
$ (this). attr ("checked", false);
});
}
});
});
</script>
<body>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<label>
<input name= "checkbox" type= "checkbox" id= "Checkboxall"/>
</label>
All
<label>
<input type= "checkbox" Name= "CheckBox2" id= "CheckBox2"/>
1</label>
<label>
<input type= "checkbox" Name= "Checkbox3" id= "Checkbox3"/>
2</label>
<label>
<input name= "checkbox4" type= "checkbox" id= "Checkbox4"/>
3</label>
<div id= "Checkshow" ></div>
jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and related
Set up:
Gets the value of a set of radio selected items: var item = $ (' input[name=items][checked] '). Val ();
Gets the text of the Select selected item var item = $ ("select[@name =items] option[@selected]"). text (); Gets the literal of the Select item: var item = $ ("Select[name =items] option[selected] "). Text (); or $ ("Select[name=items]"). Find ("option:selected"). Text ();
The second element of the Select Drop-down box is the currently selected value: $ (' #select_id ') [0].selectedindex = 1;
Select Drop-down Box value = ' val ' element is currently selected: $ ("Select[name=items] option[value= ' val '"). attr ("Selected", "Selected");
The second element of the radio Radio Group is the current check: $ (' input[@name =items] '). Get (1). checked = true; or $ (' input[name=items] '). attr ("Checked", ' 1′);
The Radio value = ' val ' element is currently selected: $ (' input[name=items][value= ' Val ']). attr ("Checked", "checked");
<script type=text/javascript>
function Addmem () {
var followers = document.getelementsbyname ("followers");
var f_str = ' 0 ';
$ ("input[@name = ' followers ']"). each (function () {
if ($ (this). attr ("checked") ==true) {
F_str + = "," +$ (This). attr ("value");
}
})
alert (F_STR);
}
</script>
See a jquery all Select/Deselect checkbox
<input type= "checkbox" Name= "checkbox_name[" id= checkbox_name_1′/>1<br
<input type= "checkbox" Name= "checkbox_name[" id= checkbox_name_2′/>2<br
<input type= "checkbox" Name= "checkbox_name[" id= checkbox_name_3′/>3<br
<input type= "checkbox" Name= "checkbox_name[" id= checkbox_name_4′/>4<br
<input type= "checkbox" Name= "Checkedall" id= "Checkedall"/> Select All/Cancel All selection
<script type= "Text/javascript"
<!--
$ (function () {
$ ("#checkedall"). Click (function () {
if ($ (this). attr ("checked") = = True) {//Select all
$ ("input[@name = ' checkbox_name[]"). each (function () {
$ (this). attr ("Checked", true);
});
} else {//deselect all
$ ("input[@name = ' checkbox_name[]"). each ( function () {
$ (this). attr ("checked", false);
});
}
});
});
//-->
</script>