jquery在表格中的全选、不选,下面全选,全选勾选中,下面一项没有选,全选勾未选中,并且带出请求值。

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript" src="../js/jquery.min.js" ></script>
		<style>
		    body{
		    	font-family: "微软雅黑";
		    	font-size: 14px;
		    }
		    .t_table{
				border-collapse:collapse;
		    }
			.t_head{
				text-align: center;
				height:40px;
				line-height: 40px;
			}
			.t_head th{
				width:200px;
				border:1px solid #d7d7d7;
			}
			.tbody{
				height: 40px;
				line-height: 40px;
				text-align: center;
			}
			.tbody td{
				border:1px solid #d7d7d7;

			}
		</style>
	</head>
	<body>
		<table class="t_table">
			<tr class="t_head">
				<th><input type="checkbox" class="all"/></th><th>学号</th><th>姓名</th><th>年龄</th><th>增加</th>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="1" class="aaa">1</td><td>张三</td><td>19</td><td>增加</td>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="2" class="aaa">2</td><td>小磊</td><td>20</td><td>增加</td>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="3" class="aaa">3</td><td>小月</td><td>21</td><td>增加</td>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="4" class="aaa">4</td><td>小张</td><td>20</td><td>增加</td>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="5" class="aaa">5</td><td>小李</td><td>20</td><td>增加</td>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="6" class="aaa">6</td><td>小王</td><td>21</td><td>增加</td>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="7" class="aaa">7</td><td>小丽</td><td>22</td><td>增加</td>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="8" class="aaa">8</td><td>小红</td><td>19</td><td>增加</td>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="9" class="aaa">9</td><td>小明</td><td>18</td><td>增加</td>
			</tr>
			<tr class="tbody">
				<td><input type="checkbox"/></td><td id="10" class="aaa">10</td><td>小海</td><td>20</td><td>增加</td>
			</tr>
		</table>
		<script>
			$(function(){
				var selectArr = [],
				    len = $(".tbody").length;
				$(".all").click(function(){
					if(this.checked){
						$(".tbody").each(function(i,item){
							//$(".tbody").eq(i).find(":checkbox").attr("checked", true);  is_ok
							//$(item).find(":checkbox").attr("checked", true); is_ok
							$(this).find(":checkbox").prop("checked", true);
							var this_id = $(this).find(".aaa").attr("id");
							var index = selectArr.indexOf(this_id);
							if(index == -1){
								selectArr.push(this_id);
							}
						})
					}else{
						$(".tbody input:checkbox").prop("checked", false);
						selectArr = [];
					}
					console.log(selectArr);

				});

				$(".tbody").click(function(){
					var isSelected = $(this).find(":checkbox").prop("checked"),
						this_id = $(this).find(".aaa").attr("id"),
						index = selectArr.indexOf(this_id);
					if(isSelected){
						if(index == -1){
							selectArr.push(this_id);
						}
					}else{
						if(index > -1){
							selectArr.splice(index,1);
						}
					}
					if(len === selectArr.length){
						$(".all").prop("checked",true);
					}else{
						$(".all").prop("checked",false);
					}
					console.log(selectArr);
				})
			})
		</script>
	</body>
</html>

  

 jquery中方法$.prop与$.attr方法有些许不同。prop用在固有html的属性时,而attr通常用在我们自定义的属性的时候。

所以区别在这里:

<input id="chk1" type="checkbox" /> 没有checked属性的多选框
<input id="chk2" type="checkbox" checked="true" />有checked属性的多选框

  prop方法结果如下:

$("#chk1").prop("checked") == false
$("#chk2").prop("checked") == true 
attr方法结果如下:
$("#chk1").attr("checked") == undefined
$("#chk2").attr("checked") == "true"

  也考虑到分页中,最后一页选项并不是10条选项的表格列表

				
时间: 2025-01-04 21:48:10

jquery在表格中的全选、不选,下面全选,全选勾选中,下面一项没有选,全选勾未选中,并且带出请求值。的相关文章

使用jquery合并表格中相同文本的相邻单元格

一.效果 二.代码 <!DOCTYPE HTML> <html> <head> <title>Example</title> <meta charset="utf-8"/> <style></style> <script src="js/jquery-2.1.4.min.js"></script> </head> <body>

Jquery实现表格中的查看删除修改

首先我们在学习js的时候就有接触到表格中的一些操作,那么Jquery是一个兼容多浏览器的轻量级的javascript库,它的核心理念是写的更少,做的更多. 现在就用学到的Jquery来做一个表格中的查看删除修改感受一下Jquery的强大. 第一步:我们编写html页 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

JQuery 获取表格中的数据

举个例子 var arr = $('#table tbody tr td:nth-child(2)') //根据id依次找到表格中的td,而后取每列的第二个值 .map(function () { return $(this).text() }) // 使用 map 对每一个 td 进行处理,function为回调函数,返回每个元素的text .get(); // 将对象集合转换为数组 另外还可以在后面.join(",") 这将转换成字符串. jQuery下有个概念叫"类数组

jquery实现表格中各项的全选

通过表格上下的两个全选checkbox对表格子项的全选!注意使用prop(),而非attr()方法.prop()返回的是标准属性true和false.

jquery获取表格中动态单元格内单选框和多选框的值

1.通过table的Id获取到每行(tr)的元素, $("#table_xuan tr") 如果过滤第一行和最后一行 $("#table_xuan tr:not(:first):not(:last)") 2.通过 each()函数遍历 每一行 $("#table_xuan tr").each(function(i)){ // i 代表的是行数 $(this).children("td").each(function(j)){

jQuery选择表格中的列

以选择table中的第一列为例: 方式1: $("table tr").find("td:first").html("first column");//错误写法:$("table tr td:first").html("first column"); 方式2: $("table tr").each(function(){ $(this).find("td:eq(0)"

JQUERY 对 表格中的数据重排序

function reIndex(){ var len1 = $('#table').find('tr').length; for(i = 1; i < len1; i++){ $("#table tr").eq(i).children("td").eq(1).html(i); } }

Jquery在表格中搜索关键字

<!DOCTYPE html><html><head> <title>ddd</title></head><body><table border="1"> <thead> <tr colspan="3"> <input type="text" id="filtertxt"> <input t

jqgrid 表格中筛选条件的多选下拉,树形下拉 ;文本框清除插件;高级查询多条件动态筛选插件

/** * @@desc 文本框清除按钮,如果isAutoWrap为false当前文本框父级必须是relative定位,boostrap参考input-group * @@author bear.LEE <571115139#qq.com> * @@since 2018-08-21 **/ ; (function ($) { $.fn.extend({ addClearBtn: function (options, $o) { var deft = { symbolClass: "f