zoukankan      html  css  js  c++  java
  • [转]jquery遍历table的tr获取td的值

    html代码:

     1 <tbody id="history_income_list">
     2 <tr>
     3 <td align="center"><input type="text" class="input-s input-w input-hs"></td>
     4 <td align="center"><input type="text" class="input-s input-w input-hs"></td>
     5 <td align="center"><input type="text" class="input-s input-w input-hs"></td>
     6 <td align="center"><a class="" onclick="history_income_del(this);" href="###">删除</a></td>
     7 </tr>
     8 <tr>
     9 <td align="center"><input type="text" class="input-s input-w input-hs"></td>
    10 <td align="center"><input type="text" class="input-s input-w input-hs"></td>
    11 <td align="center"><input type="text" class="input-s input-w input-hs"></td>
    12 <td align="center"><a class="" href="###">删除</a></td>
    13 </tr>
    14 <tr>
    15 <td align="center"><input type="text" class="input-s input-w input-hs"></td>
    16 <td align="center"><input type="text" class="input-s input-w input-hs"></td>
    17 <td align="center"><input type="text" class="input-s input-w input-hs"></td>
    18 <td align="center"><a class="" href="###">删除</a></td>
    19 </tr>
    20 </tbody>
    21   

     

    方法一:

    var trList = $("#history_income_list").children("tr")
        for (var i=0;i<trList.length;i++) {
            var tdArr = trList.eq(i).find("td");
            var history_income_type = tdArr.eq(0).find("input").val();//收入类别
            var history_income_money = tdArr.eq(1).find("input").val();//收入金额
            var history_income_remark = tdArr.eq(2).find("input").val();//    备注
            
            alert(history_income_type);
            alert(history_income_money);
            alert(history_income_remark);
        }

    方法二:

    $("#history_income_list").find("tr").each(function(){
            var tdArr = $(this).children();
            var history_income_type = tdArr.eq(0).find("input").val();//收入类别
            var history_income_money = tdArr.eq(1).find("input").val();//收入金额
            var history_income_remark = tdArr.eq(2).find("input").val();//    备注
            
            alert(history_income_type);
            alert(history_income_money);
            alert(history_income_remark);
            
            
        });
  • 相关阅读:
    Hive表中四种不同数据导出方式以及如何自定义导出列分隔符
    build doris 0.11.5 on centos 7/ubuntu
    centos7 gcc升级
    linux-nohup后台运行
    sqoop import mysql to hive table:GC overhead limit exceeded
    Hive开启mapjoin优化、并行执行、动态分区
    How to Plan and Configure YARN and MapReduce 2 in HDP 2.0
    Android 8 AudioPolicy 初始化
    Android 8 声音调整过程
    qcom wlan kernel 解读 WCNSS_qcom_cfg.ini 文件
  • 原文地址:https://www.cnblogs.com/CQ-LQJ/p/5474315.html
Copyright © 2011-2022 走看看