$(
function
() {
// 全选
$(
"#btnCheckAll"
).bind(
"click"
,
function
() {
$(
"[name = chkItem]:checkbox"
).attr(
"checked"
,
true
);
});
// 全不选
$(
"#btnCheckNone"
).bind(
"click"
,
function
() {
$(
"[name = chkItem]:checkbox"
).attr(
"checked"
,
false
);
});
// 反选
$(
"#btnCheckReverse"
).bind(
"click"
,
function
() {
$(
"[name = chkItem]:checkbox"
).each(
function
() {
$(
this
).attr(
"checked"
, !$(
this
).attr(
"checked"
));
});
});
// 全不选
$(
"#btnSubmit"
).bind(
"click"
,
function
() {
var
result =
new
Array();
$(
"[name = chkItem]:checkbox"
).each(
function
() {
if
($(
this
).is(
":checked"
)) {
result.push($(
this
).attr(
"value"
));
}
});
alert(result.join(
","
));
});
});
Problem Description: The first point to select All can, and then click on the whole selection, then click on the Select all, all do not select, the reverse selection will not react, and later with other browsers to send can, so the feeling is compatibility problem, later access to the data found that is true, reference address http://jquery.com/
Solution: Change the attr to prop can, after verifying that each browser is good, the official website is recommended after 1.6 with prop, in this record for later use.
JQuery checkbox Check prop and attr attention point analysis