书写一个后台管理中用到的全选反选功能。代码如下

<!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>

效果图如下:

jquery 书写全选反选功能的更多相关文章

  1. jquery实现全选/反选功能

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  2. jQuery实现全选反选功能

    废话不说,直接上代码! <html> <head> <meta http-equiv="Content-Type" content="tex ...

  3. python: jquery实现全选 反选 取消

    引入这个jquery-1.12.4.js jquery实现全选 反选 取消 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitio ...

  4. JavaScript 实现全选 / 反选功能

    JavaScript 实现全选 / 反选功能 版权声明:未经授权,内容严禁转载! 构建主体界面 编写 HTML 代码 和 CSS 代码,设计主题界面 <style> #user { wid ...

  5. JS全选反选功能

    总选框:<input type="checkbox" class="all" name="all"> 子选框: <inpu ...

  6. jQuery实现全选/反选和批量删除

    <%@ page language="java" contentType="text/html; charset=utf-8"     pageEncod ...

  7. JQuery实现列表中复选框全选反选功能封装

    我们在做列表的时候经常会遇到全选,反选进行批量处理问题,例如: 我当时就是简单的实现了,然后想封装到公共的js中,封装的太烂,不好意思贴出来了(就是把实现代码之间放到公共js中,然后每个页面都用固定的 ...

  8. C# WinForm中实现CheckBox全选反选功能

    今天一群里有人问到这个功能,其实应该挺简单,但提问题的人问题的出发点并没有描述清楚.因此,一个简简单单的需求,就引起了群内热烈的讨论.下面看看这个功能如何去实现,先上效果: 下面直接上代码,请不要在意 ...

  9. jquery 实现全选反选

    jquery代码 $(function () { $('#inputCheck').click(function () { if ($(this).attr("checked")) ...

随机推荐

  1. jquery阻止事件的两种实现方式

    再阻止事件冒泡的方面,jquery有两种方式: 一种是 return false;另外一种是 e.stopPropagation() html代码 <form id="form1&qu ...

  2. html网页音乐播放器自带播放列表

    基于网页的音乐播放器demo  http://pan.baidu.com/s/1dDgm7HR 自己diy了一个手机端在线音乐播放器演示地址http://shanxi2014.com/zhuandiz ...

  3. 【WPF】Dispatcher及线程操作

    WPF 应用程序启动后,会有两个线程: 1. 一个是用来处理UI呈现(处理UI的请求,比如输入和展现等操作). 2. 一个用来管理 UI的 (对UI元素及整个UI进行管理). 像Winform一样,W ...

  4. Android WebView缓存分析

    http://blog.csdn.net/a345017062/article/details/8703221   WebView的缓存可以分为页面缓存和数据缓存. 页面缓存是指加载一个网页时的htm ...

  5. 2-3 tree使用

    The 2-3 tree is also a search tree like the binary search tree, but this tree tries to solve the pro ...

  6. 【CF】283D Tennis Game

    枚举t加二分判断当前t是否可行,同时求出s.注意不能说|a[n]| <= |3-a[n]|就证明无解,开始就是wa在这儿了.可以简单想象成每当a[n]赢的时候,两人都打的难解难分(仅多赢一轮): ...

  7. [FJSC2014]圈地

    [题目描述] 2维平面上有n个木桩,黄学长有一次圈地的机会并得到圈到的土地,为了体现他的高风亮节,他要使他圈到的土地面积尽量小.圈地需要圈一个至少3个点的多边形,多边形的顶点就是一个木桩,圈得的土地就 ...

  8. sharepoint 2010 如何创建文档库内容类型content type

    转:http://biancheng.dnbcw.info/linux/441643.html 这次主要是记录下,如何来创建文档内容类型,例如新建文档的时候,可以选择不同模板,有word,excel文 ...

  9. _GUN_SOURCE宏

    问题描述:在编译程序时,提示一个错误和一个警告. error:storage size of tz isn’t know: 其中tz是struct timezone类型的变量. warning:imp ...

  10. 动态规划(树形DP):LNOI 2016 侦察守卫

    Sample Input 12 2 8 9 12 6 1 1 5 1 4 8 10 6 10 1 2 3 5 6 7 8 9 10 11 1 3 2 3 3 4 4 5 4 6 4 7 7 8 8 9 ...