jquery 书写全选反选功能
来源:互联网 发布:不为谁而作的歌 知乎 编辑:程序博客网 时间:2024/06/08 06:15
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>全选反选插件</title>
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div class="container">
<div class="row6">
<table class="table table-bordered">
<thead>
<tr>
<th style="width:250px;">
<button type="button" class="btn btn-success" id="check_all">全选</button>
<button type="button" class="btn btn-danger" id="check_others">反选</button>
</th>
<th>ID</th>
<th>name</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" class="son_checkbox" ></td>
<td>1</td>
<td>张三</td>
</tr>
<tr>
<td><input type="checkbox" class="son_checkbox" ></td>
<td>2</td>
<td>李四</td>
</tr>
<tr>
<td><input type="checkbox" class="son_checkbox" ></td>
<td>3</td>
<td>王五</td>
</tr>
<tr>
<td><input type="checkbox" class="son_checkbox" ></td>
<td>4</td>
<td>赵六</td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
$(function(){
//点击全选事件
$("#check_all").click(function(){
var text=$(this).text();
var status;
if(text=="全选")
{
status=true;
text="取消全选";
}
else if(text=="取消全选")
{
status=false;
text="全选";
}else
{
return false;
}
$(".son_checkbox").prop("checked",status);//改变状态
$(this).text(text);//设置文字
});
//点击反选事件
$("#check_others").click(function(){
//遍历所有选择框 然后反转状态
$(".son_checkbox").each(function(){
var now_status=$(this).prop("checked");//获取当前选择框是否选中
now_status=!now_status;//反转状态
$(this).prop("checked",now_status);//重新绑定状态
});
});
});
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>全选反选插件</title>
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div class="container">
<div class="row6">
<table class="table table-bordered">
<thead>
<tr>
<th style="width:250px;">
<button type="button" class="btn btn-success" id="check_all">全选</button>
<button type="button" class="btn btn-danger" id="check_others">反选</button>
</th>
<th>ID</th>
<th>name</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" class="son_checkbox" ></td>
<td>1</td>
<td>张三</td>
</tr>
<tr>
<td><input type="checkbox" class="son_checkbox" ></td>
<td>2</td>
<td>李四</td>
</tr>
<tr>
<td><input type="checkbox" class="son_checkbox" ></td>
<td>3</td>
<td>王五</td>
</tr>
<tr>
<td><input type="checkbox" class="son_checkbox" ></td>
<td>4</td>
<td>赵六</td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
$(function(){
//点击全选事件
$("#check_all").click(function(){
var text=$(this).text();
var status;
if(text=="全选")
{
status=true;
text="取消全选";
}
else if(text=="取消全选")
{
status=false;
text="全选";
}else
{
return false;
}
$(".son_checkbox").prop("checked",status);//改变状态
$(this).text(text);//设置文字
});
//点击反选事件
$("#check_others").click(function(){
//遍历所有选择框 然后反转状态
$(".son_checkbox").each(function(){
var now_status=$(this).prop("checked");//获取当前选择框是否选中
now_status=!now_status;//反转状态
$(this).prop("checked",now_status);//重新绑定状态
});
});
});
</script>
</body>
</html>
0 0
- jquery 书写全选反选功能
- Jquery实现全选反选功能
- JQuery(全选与反选功能)
- jQuery实现全选于反选功能
- Jquery 实现全选反选功能
- jquery实现全选反选功能
- jQuery实现全选反选功能
- Jquery之实现全选反选功能
- jquery实现反选、全选、全不选功能
- jquery全选反选
- jquery 全选反选
- Jquery 全选、反选
- jquery -全选/反选
- Jquery 全选,反选
- Jquery 全选 反选
- jquery全选反选
- jquery--全选反选
- jQuery全选反选
- A.单词反转
- 嵌入式Linux开发介绍
- Oracle
- 2017面试题大汇总
- L3-002. 堆栈
- jquery 书写全选反选功能
- 回溯算法概括
- OpenGL画点
- 几种常见较经典的显著性检测算法
- Unix环境高级编程第三版中apue.h头文件如何配置
- Java——进程
- 【量化入门】通过几种常见的量化策略框架,学习量化炒股
- [BZOJ1415][Noi2005]聪聪和可可(bfs+概率期望+记搜)
- STM32数据类型