【问题标题】:How to get the first row's last column of an Html table using jQuery如何使用jQuery获取Html表的第一行的最后一列
【发布时间】:2010-10-06 10:51:59
【问题描述】:

我有一个 html 表,我需要获取第一行的(不是 thead 部分。它将在 tbody 部分)最后一列的值或文本。我需要点击按钮时的值btnAdd

 <table>
    <thead>
    <tr>
    <td>Name</td>
    <td>ID</td>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>Edwin</td>
    <td><span style='display:none'>1</span></td>
    </tr>
    </tbody>
    </table>
   <input type='btnAdd' runat='server' >

【问题讨论】:

    标签: jquery html


    【解决方案1】:
    $('table tbody tr:first td:last').text()
    

    【讨论】:

    • 不会选择第一行的最后一个单元格吗? thead 里面是哪个?
    • 我正在使用 ID 访问?那么我可以使用#tbl 代替表格吗? #tbl 是我的餐桌 ID
    【解决方案2】:

    我认为这应该可行:

    $('btnAdd').click(
        function(){
           var text = $('tbody > tr:first > td:last').text();
        });
    

    【讨论】:

      【解决方案3】:
      $("button").click(function(){
         var columnText = $("TABLE TBODY TR:first TD:last").html();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-03
        • 2012-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-09
        • 1970-01-01
        • 2011-01-16
        相关资源
        最近更新 更多