jquery全选反选
2016-06-16 14:27
295 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery全选反选</title>
<script language="javascript" src="js/jquery-1.6.4.min.js"></script>
</head>
<script>
$(document).ready(function(){
var i=true
var box=$("input:checkbox")
var check1=$("input:button[name='quanxuan']")
var check2=$("input:button[name='fanxuan']")
/* check1.click(function(){
if(i){
box.prop("checked",true);
i=false;
}else{
box.prop("checked",false);
i=true;
}
});*/
check1.toggle(
function(){
box.prop("checked",true);
},function(){
box.prop("checked",false);
}
)
check2.click(function(){
box.each(function() {
if($(this).prop("checked")){
$(this).prop("checked",false)
}else{
$(this).prop("checked",true)
}
});
});
})
</script>
<body>
<div style="width:500px; height:200px; margin:100px auto;">
<label>
<input type="checkbox" /> 网店美工
</label>
<label>
<input type="checkbox" /> 前端工程师
</label>
<label>
<input type="checkbox" /> 网店美工
</label>
<label>
<input type="checkbox" /> 前端工程师
</label><br />
<input type="button" value="全选" name="quanxuan" />
<input type="button" value="反选" name="fanxuan" />
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery全选反选</title>
<script language="javascript" src="js/jquery-1.6.4.min.js"></script>
</head>
<script>
$(document).ready(function(){
var i=true
var box=$("input:checkbox")
var check1=$("input:button[name='quanxuan']")
var check2=$("input:button[name='fanxuan']")
/* check1.click(function(){
if(i){
box.prop("checked",true);
i=false;
}else{
box.prop("checked",false);
i=true;
}
});*/
check1.toggle(
function(){
box.prop("checked",true);
},function(){
box.prop("checked",false);
}
)
check2.click(function(){
box.each(function() {
if($(this).prop("checked")){
$(this).prop("checked",false)
}else{
$(this).prop("checked",true)
}
});
});
})
</script>
<body>
<div style="width:500px; height:200px; margin:100px auto;">
<label>
<input type="checkbox" /> 网店美工
</label>
<label>
<input type="checkbox" /> 前端工程师
</label>
<label>
<input type="checkbox" /> 网店美工
</label>
<label>
<input type="checkbox" /> 前端工程师
</label><br />
<input type="button" value="全选" name="quanxuan" />
<input type="button" value="反选" name="fanxuan" />
</div>
</body>
</html>
相关文章推荐
- jquery一句话全选/取消全选
- 基于jquery实现复选框全选,反选,全不选等功能
- jquery实现全选和全不选功能效果的实现代码【推荐】
- asp.net gridview中用checkbox全选的几种实现的区别
- js全选按钮的实现方法
- JS实现CheckBox复选框全选、不选或全不选功能
- 关于树形菜单 Checkbox的全选
- javascript实现简单的全选和反选功能
- jquery checkbox全选反选效果代码
- Jquery 全选反选实例代码
- jquery 全选、全不选、反选效果的实现代码【推荐】
- 利用jQuery实现CheckBox全选/全不选/反选的简单代码
- jquery自定义右键菜单、全选、不连续选择
- jquery实现简单的全选和反选功能
- 小博老师演示常用JQuery效果 ——复选框全选和反选效果
- 利用jQuery实现全选、全不选、反选(checkBox)
- 使用jQuery实现全选、全不选、 反选(button)
- 利用js实现全选、反选、全不选(button)
- jQuery on()方法绑定动态元素的点击事件实例代码浅析
- jQuery页面元素动态添加后绑定事件丢失方法,非 live