欢迎您访问我爱IT技术网,今天小编为你分享的javascript教程:【jquery写个checkbox——类似邮箱全选功能】,下面是详细的讲解!
jquery写个checkbox——类似邮箱全选功能
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>checkbox</title>
</head>
<body>
<input type="checkbox" name="btn" id="btn"/><label for="btn">全选/全不选</label><br/>
<input type="checkbox" name="choose" id="checkbox1"/><label for="checkbox1">选项1</label><br/>
<input type="checkbox" name="choose" id="checkbox2"/><label for="checkbox2">选项2</label><br/>
<input type="checkbox" name="choose" id="checkbox3"/><label for="checkbox3">选项3</label><br/>
<input type="checkbox" name="choose" id="checkbox4"/><label for="checkbox4">选项4</label><br/>
<input type="checkbox" name="choose" id="checkbox5"/><label for="checkbox5">选项5</label><br/>
<input type="checkbox" name="choose" id="checkbox6"/><label for="checkbox6">选项6</label><br/>
<input type="checkbox" name="choose" id="checkbox7"/><label for="checkbox7">选项7</label><br/>
<input type="checkbox" name="choose" id="checkbox8"/><label for="checkbox8">选项8</label><br/>
<input type="checkbox" name="choose" id="checkbox9"/><label for="checkbox9">选项9</label><br/>
<input type="checkbox" name="choose" id="checkbox10"/><label for="checkbox10">选项10</label><br/>
<a href="http://www.jb51.net/article/javascript:;" id="btn2">反选</a>
</body>
</html>
<script type="text/javascript" src="http://www.jb51.net/js/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
var checkboxes=$('input[name=choose]');
var btn=$('#btn');
var btn2=$('#btn2');
btn.click(function(){
checkboxes.attr('checked',this.checked);
});
checkboxes.click(function(){
var flag=true;
checkboxes.each(function(){
if(!this.checked) flag=false;
});
btn.attr('checked',flag);
});
btn2.click(function(){
var flag=true;
checkboxes.each(function(){
this.checked=!this.checked;
if(!this.checked) flag=false;
});
btn.attr('checked',flag);
});
});
</script>
关于jquery写个checkbox——类似邮箱全选功能的用户互动如下:
相关问题:jquery怎么实现全选复选框?
答:$('#checkedAll').click(function(){ if(this.checked){/*对默认是否为选中进行判断*/ // $('[name=checkboxt]:checkbox').attr('checked',true);/*checked为true时为默认显示的状态,为true实现全选功能*/ // }else{ / $('[name=checkboxt]:chec... >>详细
相关问题:jquery checkbox 全选反选代码只能执行一遍,第二...
答:removeAttr参数只需要一个,removeAttr("checked") 不过建议替换成 $(".chooseall").click(function(){ if($(".chooseall").prop("checked") == true){ $("input[name='checkbox1']").prop("checked", false); console.log(1); }else{ $("input[... >>详细
相关问题:jquery实现 点击复选框,勾选所有复选框,再次点击...
答:全选/反选 checkbox 的 id = 'all' 其他checkbox的name=‘check’ $("#all").click(function(){ if($("#all").attr("checked") == "checked"){ $("input[name='check']").attr("checked","checked"); }else{ $("input[name='check']").removeAttr(... >>详细
- 【firefox】firefox浏览器不支持innerText的解决
- 【Extjs】Extjs学习过程中新手容易碰到的低级错误
- 【clearInterval】js clearInterval()方法的定义
- 【ComboBox】ComboBox 和 DateField 在IE下消失的
- 【ajax】用js来解决ajax读取页面乱码-页面乱码
- 【dom】javascript dom追加内容实现示例-追加内容
- 【has】基于jquery的has()方法以及与find()方法以
- 【extjs】Extjs入门之动态加载树代码-动态加载树
- 【checkbox】让checkbox不选中即将选中的checkbox
- 【angularjs_scope】AngularJS中监视Scope变量以
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
