jquery通过prop来对checkbox进行全选
2016-08-19 13:32
337 查看
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>
.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>
相关文章推荐
- 新版本的jquery checkbox 全选反选代码只能执行一遍,第二次就失败attr与prop区别
- 1、checkbox日常jquery操作。 现在我们以下面的html为例进行checkbox的操作。 <input id="checkAll" type="checkbox" />全选
- Jquery中对checkbox的各种“全选”或者“取消”功能实现(特别注意1.6+的一定不能使用attr来取属性了!用prop!)
- 通过jquery获取后台传过来的值进行全选
- jQuery使用prop设置checkbox全选、反选
- 通过jQuery遍历div里面的checkbox,实现全选的功能
- (javascript,treeview)treeview通过checkbox来进行全选单选
- GridView中通过js对CheckBox进行全选
- jquery .prop()的相关操作——全选、反选、获得所有选中的checkbox
- jquery通过prop函数验证checkbox是否选中
- jQuery使用prop设置checkbox全选、反选
- jquery checkbox 全选 不要用attr要用 prop
- jquery 使用attr方法对checkBox进行全选和反选操作
- 通过Jquery全选或全部取消某个table的checkbox
- jQuery checkbox 全选、全取消
- jQuery checkbox 全选,取消全选
- 如何进行CheckBox的全选呢?
- Jquery实现操作Gridview中的Checkbox全选
- jQuery操作checkbox的例子(全选,反选,获取选取值)【转】
- jquery实现checkbox全选、取消全选