jquery通过prop来对checkbox进行全选

jquery判断checked的三种方法:

.attr(‘checked’):   //看版本1.6+返回:”checked”或”undefined” ;1.5-返回:true或false
.prop(‘checked’): //16+:true/false
.is(‘:checked’):    //所有版本:true/false

jquery赋值checked的几种写法:

所有的jquery版本都可以这样赋值:

// $(“#cb1″).attr(“checked”,”checked”);
// $(“#cb1″).attr(“checked”,true);

jquery1.6+:prop的4种赋值:

// $(“#cb1″).prop(“checked”,true);
// $(“#cb1″).prop({checked:true}); //map键值对
// $(“#cb1″).prop(“checked”,function(){
return true;//函数返回true或false
});

$(“#cb1″).prop(“checked”,”checked”);


function chAll(ch_id){
       if($('input[name="ck_all"]').prop("checked")){
           $('input[name="'+ch_id+'"]').prop("checked",true);
       }else{
           $('input[name="'+ch_id+'"]').prop("checked",false);
       }
       
   }


<table class="table table-hover table-bordered">
               <thead>
                 <th width="4%"><input type="checkbox" name="ck_all" onclick="chAll('ck_id');"/></th>
                 <th width="5%">序号</th>
                 <th width="20%">姓名</th>
                 <th width="10%">年龄</th>
                 <th width="10%">性别</th>
                 <th width="30%">备注</th>
                 <th width="10%">操作</th>
               </thead>
               <tbody>
                 <c:forEach items="${page.list}" var="user" varStatus="status">
                 <tr>
                    <td><input type="checkbox" name="ck_id" value="${user.id}"/></td>
                    <td>${(status.index+1)+page.pageSize*(page.pageNumber-1)}</td>
                    <td><a href="javascript:void(0);" onclick="jumpToFrame('/user/show/${user.id}-readonly');">${user.name }</a></td>
                    <td>${user.age }</td>
                    <td>${user.sex==1?'男':'女' }</td>
                    <td>${user.remark }</td>
                    <td>
                      <button type="button" class="btn btn-primary btn-sm" onclick="locationHref('${ctx}/user/show/${user.id }');">修改</button>
                      <button type="button" class="btn btn-danger btn-sm" onclick="locationHref('${ctx}/user/del/${user.id }');">删除</button>
                 </tr>
                 </c:forEach>
               </tbody>
            </table>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值