<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JQ实现正、反选</title>
</head>
<body>
<table border="1px" style="width: 200px;margin-bottom: 10px">
<thead>
<tr>
<th>#</th>
<th>姓名</th>
<th>性别</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox"></td>
<td>Alex</td>
<td>女</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>Egon</td>
<td>女</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>Qimi</td>
<td>女</td>
</tr>
</tbody>
</table>
<input type="button" value="全选" id="i1" class="c1">
<input type="button" value="反选" id="i2" class="c1">
<input type="button" value="取消" id="i3">
<script src="jquery-3.2.1.js"></script>
<script>
// <!-----------------------------------全选------------------------------------>
var $in_1 = $("#i1");
//用第一种循环的方式全部选中,each的循环体不用加索引取值
// $in_1.on("click",function () {
// var $cheele = $(":checkbox");
// $cheele.each(function () {
// //为input标签增加固有属性checked
// $(this).prop("checked",true);
// })
// });
//用第二种循环的方式全部选中
// $in_1.click("click",function () {
// var $cheele = $(":checkbox");
// $.each($cheele,function () {
// $(this).prop("checked",true);
// })
// });
//另一种全选的方法
//要执行的语句不能直接你跟在","之后!!!
$in_1.on("click",function () {
$(":checkbox").prop("checked",true);
});
//-----------------------------------------取消--------------------------------------------------
var $in_2 = $("#i3");
$in_2.on("click",function () {
$(":checkbox").prop("checked",false);
});
//-----------------------------------------反选--------------------------------------------------
var $in_3 = $("#i2");
$in_3.on("click",function () {
$(":checkbox").each(function () {
$(this).prop("checked",!$(this).prop("checked"));
})
});
</script>
</body>
</html>

JQuery实现全选、反选和取消功能的更多相关文章

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

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

  2. jquery 书写全选反选功能

    书写一个后台管理中用到的全选反选功能.代码如下 <!DOCTYPE html> <html lang="en"> <head> <meta ...

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

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

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

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

  5. jQuery实现全选反选功能

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

  6. jquery实现全选 反选 取消

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. jquery 实现全选反选

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

  8. jquery checkbox 全选反选代码只能执行一遍,第二次就失败

    遇到问题背景: 在写到购物车的全选交互的时候,商品选中的状态只有在第一次的时候可以,第二次就无法选中:(代码如下) $(".chooseall").click(function() ...

  9. jQuery checkbox全选 和全部取消

    1.chkAll选中,全部chk选中  ,chkAll取消选中,全部chk取消选中 //chkAll选中,全部chk选中 ,chkAll取消选中,全部chk取消选中 $("#chkAll&q ...

  10. js实现全选与全部取消功能

    function checkAll() { //把所有参与选择的checkbox使用相同的name,这里为"num_iid"    var eles = document.getE ...

随机推荐

  1. zfs mount

    root@47abd5c91421:/# ls /native/sbin    autopush  cryptoadm  dhcpinfo  dlstat       flowadm     ibd_ ...

  2. 分别用js和css实现瀑布流

    下午查找了瀑布流的相关原理,找了一些css3实现的还有js实现的,最后总结了一些比较简单的,易懂的整理起来 1.css3实现 只要运用到    column-count分列 column-width固 ...

  3. 【FZU2178】礼物分配

    题意 在双胞胎兄弟Eric与R.W的生日会上,他们共收到了N个礼物,生日过后他们决定分配这N个礼物(numv+numw=N).对于每个礼物他们俩有着各自心中的价值vi和wi,他们要求各自分到的礼物数目 ...

  4. 前向渲染路径细节 Forward Rendering Path Details

    正向渲染路径细节 Forward Rendering Path Details Forward Rendering path renders each object in one or more pa ...

  5. loadrunner添加load generator连接失败解决办法

    1.到防火墙设置里面“允许程序和功能通过windows防火墙”,然后添加Loadrunner Agent Procss,到列表中,在“专用”和“公用”打勾,然后重启一下LR和Loadrunner Ag ...

  6. Python爬虫实战一之爬取糗事百科段子

    大家好,前面入门已经说了那么多基础知识了,下面我们做几个实战项目来挑战一下吧.那么这次为大家带来,Python爬取糗事百科的小段子的例子. 首先,糗事百科大家都听说过吧?糗友们发的搞笑的段子一抓一大把 ...

  7. js改变触发

    onchange="doEmpty($(this))"

  8. LWIP内存管理

    LWIP是一种TCP/IP协议栈,与嵌入式操作系统一样也提供了内存管理. 内存池里面有多个同样大小的内存,不同类型的内存池其里面的内存大小不一样.

  9. StackExchange.Redis实现Redis发布订阅

    由于ServiceStack.Redis最新版已经收费,所以现在大家陆陆续续都换到StackExchange.Redis上了,关于StackExchange.Redis详细可以参看Github htt ...

  10. oracle imp使用

    1. 获取帮助 imp help=y 2. 导入一个完整数据库 imp system/manager file=bible_db log=dible_db full=y ignore=y 3. 导入一 ...