$(
function
() {
$( " #ckAll " ).click( function () {
// alert($(this).attr("checked"));
if ($( this ).attr( " checked " ) == " checked " ) {
// $("input[id*=ckID]") 选取ID有ckID的input控件
$( " input[id*=ckID] " ).each( function () { this .checked = true ; });
}
else {
$( " input[id*=ckID] " ).each( function () { this .checked = false ; });
}
})
})
$( " #ckAll " ).click( function () {
// alert($(this).attr("checked"));
if ($( this ).attr( " checked " ) == " checked " ) {
// $("input[id*=ckID]") 选取ID有ckID的input控件
$( " input[id*=ckID] " ).each( function () { this .checked = true ; });
}
else {
$( " input[id*=ckID] " ).each( function () { this .checked = false ; });
}
})
})
html 代码 :
<
input
id
="chkAll"
type
="checkbox"
title
="全选/不选"
/>
< input id ="rptPoList_ctl01_chkID" type ="checkbox" />
< input id ="rptPoList_ctl02_chkID" type ="checkbox" />
< input id ="rptPoList_ctl01_chkID" type ="checkbox" />
< input id ="rptPoList_ctl02_chkID" type ="checkbox" />
我参考 网上很多代码
一般都采用:
if ($(this).attr("checked")==true)
这个方式来判断checkbox是否选中
问题在于
if ($(this).attr("checked")==true)是不是成立的
我用alert($(this).attr("checked")) ; 放在JS里,如果checkbox选中,结果显示:checked,而不是true
如果checkbox不选中,结果显示:undefined,而不是false
不知道大家 是不是相同的结果 ,看了网上大家的代码 我还是有点不解