• 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
  • 相关阅读:
    webserver服务器
    轮子哥的网站地址
    构建javaweb服务的docker镜像和容器化启动服务
    spring-cloud-alibaba-gateway
    markdown-记笔记常用语法
    java-生成公私钥命令
    阿里云oss文件服务器
    mybatis-mapper.xml一个标签支持执行多个sql语句
    docker安装nacos
    spring-cloud-alibaba-nacos
  • 原文地址:https://www.cnblogs.com/yanghucheng/p/11387609.html
Copyright © 2020-2023  润新知