jQuery操作CheckBox的方法(选中,取消,取值)
2014-04-27 21:08
716 查看
代码:
<tr>
<td>用户权限:</td>
<td>
<select id="userRight" id="groupRight" name="groupRight" style="width:200px;" onchange="selecgRight(this);">
<option value="1">系统管理员</option>
<option value="2">普通用户</option>
<option value="3">自定义权限</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="checkbox" value="1" checked name="userGroupRight">查询本人导入的检查记录</input><br>
<input type="checkbox" value="2" checked name="userGroupRight">查询所有检查记录</input><br>
<input type="checkbox" value="3" checked name="userGroupRight">查询本人的操作日志</input><br>
<input type="checkbox" value="4" checked name="userGroupRight">查询所有操作日志</input><br>
<input type="checkbox" value="5" checked name="userGroupRight">修改用户密码</input><br>
<input type="checkbox" value="6" checked name="userGroupRight">管理用户</input>
</td>
</tr>
function selecgRight(obj){
var curValue=obj.value;
if(curValue==1){
//选中所有的复选框
$("[name='userGroupRight']").attr("checked",'true');
}else if(curValue==2){
$("[name='userGroupRight']").removeAttr("checked");
$("[name='userGroupRight']").each(function(){
if($(this).val()==1){
$(this).attr("checked",'true');
}
if($(this).val()==3){
$(this).attr("checked",'true');
}
if($(this).val()==5){
$(this).attr("checked",'true');
}
})
}else{
//取消所有复选框
$("[name='userGroupRight']").removeAttr("checked");
}
}
<tr>
<td>用户权限:</td>
<td>
<select id="userRight" id="groupRight" name="groupRight" style="width:200px;" onchange="selecgRight(this);">
<option value="1">系统管理员</option>
<option value="2">普通用户</option>
<option value="3">自定义权限</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="checkbox" value="1" checked name="userGroupRight">查询本人导入的检查记录</input><br>
<input type="checkbox" value="2" checked name="userGroupRight">查询所有检查记录</input><br>
<input type="checkbox" value="3" checked name="userGroupRight">查询本人的操作日志</input><br>
<input type="checkbox" value="4" checked name="userGroupRight">查询所有操作日志</input><br>
<input type="checkbox" value="5" checked name="userGroupRight">修改用户密码</input><br>
<input type="checkbox" value="6" checked name="userGroupRight">管理用户</input>
</td>
</tr>
function selecgRight(obj){
var curValue=obj.value;
if(curValue==1){
//选中所有的复选框
$("[name='userGroupRight']").attr("checked",'true');
}else if(curValue==2){
$("[name='userGroupRight']").removeAttr("checked");
$("[name='userGroupRight']").each(function(){
if($(this).val()==1){
$(this).attr("checked",'true');
}
if($(this).val()==3){
$(this).attr("checked",'true');
}
if($(this).val()==5){
$(this).attr("checked",'true');
}
})
}else{
//取消所有复选框
$("[name='userGroupRight']").removeAttr("checked");
}
}
相关文章推荐
- jQuery+ashx实现加载更多(C#)
- Jquery笔记小节
- ichat在线客服jQuery插件(可能是历史上最灵活的)
- jQuery特效大全
- Jquery+ajax+json+servlet原理和Demo
- Get item by sharepoint web service jquery
- JQuery获取基本对象的方法
- jquery库推荐-superslide
- ExtJs与jQuery的比较
- myeclipse验证jquery错误的问题
- jQuery $.ajax传递数组的traditional参数传递必须true
- jquery获取URL参数
- 【jquery前端开发】可调整的幻灯片(图片轮播)
- jQuery常用遍历节点方法
- jquery实现复选框联动
- Dom对象和jQuery对象的相互转化
- Jquery实现仿淘宝天猫左侧分类导航插件
- jQuery基础与一些细节(2)
- 利用jQuery和CSS实现环形进度条
- window.onload 、body.onload 以及 jQuery 等dom加载完成后执行脚本的区别