JQuery 全选 反选 获取Table 中指定td的元素值

 1 //全选
 2   function initTableCheckbox() {
 3   var $thr = $('table thead tr');
 4   var $checkAllTh = $('<th><input type="checkbox" id="checkAll" name="checkAll" /></th>');
 5   /*将全选/反选复选框添加到表头最前,即增加一列*/
 6   $thr.prepend($checkAllTh);
 7   /*“全选/反选”复选框*/
 8   var $checkAll = $thr.find('input');
 9   $checkAll.click(function(event){
10   /*将所有行的选中状态设成全选框的选中状态*/
11   $tbr.find('input').prop('checked',$(this).prop('checked'));
12   /*并调整所有选中行的CSS样式*/
13   if ($(this).prop('checked')) {
14   $tbr.find('input').parent().parent().addClass('warning');
15   } else{
16   $tbr.find('input').parent().parent().removeClass('warning');
17   }
18   /*阻止向上冒泡,以防再次触发点击操作*/
19   event.stopPropagation();
20   });
21   /*点击全选框所在单元格时也触发全选框的点击操作*/
22   $checkAllTh.click(function(){
23   $(this).find('input').click();
24   });
25   var $tbr = $('table tbody tr');
26   var $checkItemTd = $('<td><input type="checkbox" name="checktb" /></td>');
27   /*每一行都在最前面插入一个选中复选框的单元格*/
28   $tbr.prepend($checkItemTd);
29   /*点击每一行的选中复选框时*/
30   $tbr.find('input').click(function(event){
31   /*调整选中行的CSS样式*/
32   $(this).parent().parent().toggleClass('warning');
33   /*如果已经被选中行的行数等于表格的数据行数,将全选框设为选中状态,否则设为未选中状态*/
34   $checkAll.prop('checked',$tbr.find('input:checked').length == $tbr.length ? true : false);
35   /*阻止向上冒泡,以防再次触发点击操作*/
36   event.stopPropagation();
37   });
38   /*点击每一行时也触发该行的选中操作*/
39   $tbr.click(function(){
40   $(this).find('input').click();
41   });
42   }
43   initTableCheckbox();
全选反选
1 if ($("[name='checktb']:checked").length == 0)
2   alert("请先选择一个采购订单!");
3   $("input[name='checktb']:checked").each(function () {
4   var trs = $(this).parents("tr");
5   var order = trs[0].cells[2].firstElementChild.text;
6   orders += order + ",";
循环获取选中项的 第三个单元格内容
1 if ($("#chkTimeout").prop("checked") == true)
2   {
3   pubT = true;
4   }else
5   {
6   pubT= false;
7   }
//判断某个框是否被选中
  1 $(function () {
  2 $(".loading_box").hide();
  3 //跳转
  4 $("#btnContinue").click(function () {
  5 window.location.href =URL.YearPersonalIndex;
  6 });
  7 //提交
  8 $("#btnSubmit").click(function () {
  9 if ($("#txtAssetCode").val() == "") {
 10 alert("请输入资产序列号");
 11 return false;
 12 }
 13 if ($("#txtAssetCode").val().length != 12) {
 14 alert("请输入12位数的资产序列号");
 15 return false;
 16 }
 17 $(".loading_box").show();
 18 $.ajax({
 19 url: URL.PersonalSubmit,
 20 type: 'Post',
 21 dataType: "json",
 22 data: { code: $("#txtAssetCode").val() },
 23 success: function (data) {
 24 if (data.suc == 2) {
 25 window.location.href = URL.YearPersonalAdd + "/?code=" + data.AsCode;
 26 
 27 } else if (data.suc == 1) {
 28 alert("盘点成功");
 29 $("#txtAssetCode").val("");
 30 }
 31 else {
 32 alert(data.msg);
 33 $("#txtAssetCode").val("");
 34 }
 35 $(".loading_box").hide();
 36 },
 37 error: function () {
 38 $(".loading_box").hide();
 39 alert("目前网络不畅通,请稍后再试!");
 40 }
 41 });
 42 
 43 });
 44 
 45 //盘盈补录
 46 $("#formYearDetail").submit(function () {
 47 if ($("#txtAssetCode").val() == "") {
 48 alert("请输入资产序列号");
 49 return false;
 50 }
 51 var reg = /^[0-9]+$/;
 52 if (!reg.test($("#txtAssetCode").val()))
 53 {
 54 alert("资产序列号只能为数字");
 55 $("#txtAssetCode").val("");
 56 return false;
 57 }
 58 if ($("#txtAssetCode").val().length != 12) {
 59 alert("请输入12位数的资产序列号");
 60 return false;
 61 }
 62 if ($("#txtAssetName").val() == "") {
 63 alert("请输入设备名称");
 64 return false;
 65 }
 66 if ($("#txtAssetName").val().length > 50) {
 67 alert("设备名称不能超过50个字");
 68 $("#txtAssetName").val("");
 69 return false;
 70 }
 71 if ($("#txtSN").val().length > 30) {
 72 alert("SN不能超过30个字");
 73 $("#txtSN").val("");
 74 return false;
 75 }
 76 if ($("#txtBrand").val().length > 50) {
 77 alert("品牌不能超过50个字");
 78 $("#txtBrand").val("");
 79 return false;
 80 }
 81 if ($("#txtModel").val().length > 50) {
 82 alert("型号不能超过50个字");
 83 $("#txtModel").val("");
 84 return false;
 85 }
 86 if ($("#txtMark").val().length > 50) {
 87 alert("备注不能超过50个字");
 88 $("#txtMark").val("");
 89 return false;
 90 }
 91 $(".loading_box").show();
 92 var params = { AssetCode: $("#txtAssetCode").val(), AssetName: $("#txtAssetName").val(),SN:$("#txtSN").val(),AssetBrand:$("#txtBrand").val(),AssetModel:$("#txtModel").val(),Remark:$("#txtMark").val() }
 93 var url = URL.PersonalAddSubmit;
 94 $.ajax({
 95 url: url,
 96 type: 'POST',
 97 dataType: "json",
 98 data: params,
 99 success: function (d) 
100 {
101 if (d.suc == 1)
102 {
103 $(".loading_box").hide();
104 alert(d.msg);
105 window.location.href = URL.YearPersonalIndex;
106 }else
107 {
108 alert(d.msg);
109 }
110 $(".loading_box").hide();
111 },
112 error: function () {
113 $(".loading_box").hide();
114 alert("目前网络不畅通,请稍后再试!");
115 }
116 });
117 
118 });
119 });
Jquery Ajax Post

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery实现功能可以通过以下步骤: 1. 给表格全选按钮和每个复框添加一个class,例如我们可以给全选按钮添加`check_all`的class,给每个复框添加`check_item`的class。 2. 监听全选按钮的click事件,当全选按钮被点击时,将所有的复框的checked属性设置为与全选按钮相。 3. 监听每个复框的click事件,当任意一个复框被点击时,检查是否所有的复框都被,如果是,则将全选按钮的checked属性设置为true,否则设置为false。 下面是一份简单的代码示例: ```html <table> <thead> <tr> <th><input type="checkbox" class="check_all"></th> <th>项1</th> <th>项2</th> <th>项3</th> </tr> </thead> <tbody> <tr> <td><input type="checkbox" class="check_item"></td> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td><input type="checkbox" class="check_item"></td> <td>4</td> <td>5</td> <td>6</td> </tr> <tr> <td><input type="checkbox" class="check_item"></td> <td>7</td> <td>8</td> <td>9</td> </tr> </tbody> </table> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(function() { // 全选/功能 $('.check_all').click(function() { $('.check_item').prop('checked', !$('.check_item').prop('checked')); }); // 功能 $('.check_item').click(function() { var is_all_checked = true; $('.check_item').each(function() { if (!$(this).prop('checked')) { is_all_checked = false; } }); $('.check_all').prop('checked', is_all_checked); }); }); </script> ``` 在上面的代码,我们首先使用jQuery监听了全选按钮和每个复框的click事件,然后实现了全选/功能。 实现全选/功能的代码非常简单,只需要在全选按钮的click事件,将所有复框的checked属性设置为与全选按钮相即可。 实现功能的代码稍微复杂一些,我们需要遍历所有的复框,检查它们是否都被,如果是,则将全选按钮的checked属性设置为true,否则设置为false。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值