jq实现全选、全不选、反选
基本思路:
1全选:点击全选按钮的时候,将input的属性checked设置为true;
2全不选:点击全不选按钮的时候,将input的属性checked设置为false;
3反选:点击反选按钮的时候,提取出当前转态的时候,已经被选中的input的索引值,然后将被选中的按钮的属性checked设置为false;没有被选中使一样的道理;
注意:想要获取到input的checked不能用attr应该用prop;checked为true的时候input被选中,checked为false的时候input未被选中;
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title> </head>
<body>
<label>全选</label><input type="checkbox" class="allclick"/>
<label>全不选</label><input type="checkbox" class="allnoclick"/>
<label>反选</label><input type="checkbox" class="noclick"/>
<div class="box">
<input type="checkbox" data-click="yes"/>
<input type="checkbox" data-click="yes"/>
<input type="checkbox" data-click="yes"/>
<input type="checkbox" data-click="yes"/>
</div>
<script src="js/jquery-1.7.2.js"></script>
<script>
$(function(){
//全选 只是针对全选
$(".allclick").click(function(){
var mark=$(".allclick").prop("checked");
if(mark==true){
$(".box input").prop("checked",true);
}
});
//全不选 只是针对全不选中
$(".allnoclick").click(function(){
var mark=$(".allnoclick").prop("checked");
if(mark==true){
$(".box input").prop("checked",false);
}
});
//反选
$(".noclick").click(function(){
$(".box input").each(function(i){
var mark=$(".box input").eq(i).prop("checked");
if(mark==true){//已经被选中
$(".box input").eq(i).prop("checked",false);
}else if(mark==false){//没有被选中
$(".box input").eq(i).prop("checked",true);
}
});
}); });
</script>
</body>
</html>
jq实现全选、全不选、反选的更多相关文章
- Jq 遍历 全选 全不选 反选
//全选 全不选 $('#checkAll').click(function () { //判断是否被选中 var bischecked = $('#checkAll').is(':checked') ...
- 基于JQ的多选/全选/反选及获取选中的值
<!-- author:青芒 --> <!DOCTYPE html> <html lang="en"> <head> <met ...
- 利用jQuery实现CheckBox全选/全不选/反选
转自:http://www.cnblogs.com/linjiqin/p/3148259.html jQuery有些版本中实现CheckBox全选/全不选/反选会有bug,经测试jquery-1.3. ...
- jquery 全选 全不选 反选
1.概述 在项目中经常遇到列表中对复选框进行勾选操作,全选...反选.. 2. example <html> <body> <form id="test-for ...
- jquery的全选/全不选/反选以及attr添加checked属性失败的解决办法
如下图: <head> <title></title> <style type="text/css"> div { border: ...
- JS实现全选、不选、反选
思路:1.获取元素.2.用for循环历遍数组,把checkbox的checked设置为true即实现全选,把checkbox的checked设置为false即实现不选.3.通过if判断,如果check ...
- springMvc接收ajax数组参数,以及jquery复选框选中、反选、全选、全不选
一.复选框选中.反选.全选.全不选 html代码: <input type='checkbox' name='menuCheckBox' value='10' >苹果 <input ...
- 【七】jquery之属性attr、 removeAttr、prop[全选全不选及反选]
全选全不选 界面: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- js实现全选/全不选、反选
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 用jQuery实现全选-全不选-反选的功能
临近过年,刚学IT没多久的小白在这里祝大家在新的一年里:新春快乐,月月赚钱,天天开心,时时快乐,分分精彩,秒秒幸福,事事顺利 古人云:学而时习之,不亦说乎. 学习后经常温习所学的知识,也是件令人愉悦的 ...
随机推荐
- 设置XtraForm标题居中
public class CustomFormPainter : FormPainter { public CustomFormPainter(Control owner, DevExpress.Sk ...
- Oracle 使用SqlPlus管理
Oracle 使用SqlPlus 安装,一键安装,很简单.安装过程,一定要记住密码 一.登陆sqlplus 连接本地服务器,可以直接,打开cmd: 可以直接不用登陆,如果登陆需要输入用户名.密码. s ...
- Django 基础(一)
Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能 ...
- View 的 focus 和 selected 状态, TabContainer实现
View的 isFocusableInTouchMode() 默认是 false, 需调用 setFocusableInTouchMode(true) 才为true要让 button 等 view 调 ...
- npm镜像
npm config set registry https://registry.npm.taobao.org // 配置后可通过下面方式来验证是否成功 npm config get registry ...
- ios打包出来为pkg的处理方法
Add LSRequiresIPhoneOS YES to your Info.plist The key can be found as Application requires iPhone en ...
- WPF控件 RichTextBox查找定位匹配字符
private void Search_Click(object sender, RoutedEventArgs e)//查询定位文本 { List<TextRange> textRang ...
- mysql临时表的产生
sql执行会生成一个巨大的临时表,当内存放不下时,要全部copy 到磁盘,导致IO飙升,时间开销增大. 额外收获知识收藏如下: 临时表存储 MySQL临时表分为"内存临时表"和&q ...
- [FFmpeg] ffmpeg 常用命令
1. 视频转换 比如一个avi文件,想转为mp4,或者一个mp4想转为ts. ffmpeg -i input.avi output.mp4 ffmpeg -i input.mp4 output.ts ...
- deep learning 练习 多变量线性回归
多变量线性回归(Multivariate Linear Regression) 作业来自链接:http://openclassroom.stanford.edu/MainFolder/Document ...