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

<!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. 你需要了解的z-index世界

    本文摘自:飘零雾雨的博客 z-index的重要性 在我看来,z-index 给了我们日常工作中以极大的帮助,我们用它来定义元素的层叠级别(stack level).受益于它,你能做Popup, Dro ...

  2. PHP实现多web服务器共享SESSION数据-session数据写入mysql数据库

    http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2010/0822/5276.html http://hi.baidu.com/lei_com/ ...

  3. Python全栈开发之 Mysql (一)

    一: 1.什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库别说我们在写程序的时候创建的database就是一个数据库 2.什么是 MySQL.Oracle.SQLi ...

  4. django查询常用操作符及models和admin的写法

    以Publisher.Author.Book的model为例子 #coding=utf-8 from django.db import models # Create your models here ...

  5. ImageList半透明,Alpha通道bug处理。

    由于ImageList的先天障碍,对alpha通道支持不好.虽然到xp有所改善,但瑕疵依然存在. 通过reflactor发现ImageList通过windows api来进行读写的.写入数据时会对原始 ...

  6. PCB设计之原理图绘制笔记

    02原理图工作环境设置原理图画布由画布和边界(Border)构成.可以通过DocumentOptions设置(快捷键DO).DocumentOptions设置--------------------- ...

  7. POJ 3026 Borg Maze bfs+Kruskal

    题目链接:http://poj.org/problem?id=3026 感觉英语比题目本身难,其实就是个最小生成树,不过要先bfs算出任意两点的权值. #include <stdio.h> ...

  8. IP工具类——IpAddress.java

    根据IP地址获取详细的地域信息,也可通过 http://whois.pconline.com.cn/ 获取地址信息. 源码如下:(点击下载  IpAddress.java) import java.i ...

  9. [CC150] Find a line passing the most number of points

    Problem: Given a two-dimensional graph with points on it, find a line which passes the most number o ...

  10. angular中实现jQuery的Document Ready

    angular中不推荐混用JQuery的,原因呢问度娘. 其实这是一个比较蛋疼的问题,尤其是angular2.0,尽量不要在页面上写js,用ts写到模块里面去吧.. 汲取各位先人的智慧,还是列一下 w ...