使用 jquery 通过 ID 获取 tfoot 值

Bot*_* FM 2 html jquery html-table

请看以下内容:

<table border="0" id="npoGridView">
            <thead>
                <tr>
                    <th>Quantity Order</th>
                    <th>Cost P.U</th>
                    <th>Total</th>
                </tr>
            </thead>
            <tbody>
                   //TD .......      
            </tbody>
               <tfoot>
                  <tr>
                    <th>Quantity Order</th>
                    <th>Cost P.U</th>
                    <th id="15">Total</th>
                  </tr>
              </tfoot>
        </table>
Run Code Online (Sandbox Code Playgroud)

我已经给tfoot中的th赋予了id (即id =“15”),现在我想使用jquery获取th值。

如何使用jquery获取表单页脚的具体th值?

the*_*dox 6

$('#npoGridView tfoot').each(function() {
  console.log($('th', this).text());
});
Run Code Online (Sandbox Code Playgroud)

获取任何特定的值,th例如<th id="15">Total</th>

$('tfoot th#15').text();
Run Code Online (Sandbox Code Playgroud)

th你可以获得如下的值:

$('tfoot th:eq(0)').text(); // output: Quantity Order

$('tfoot th:eq(1)').text(); // output: Cost P.U

$('tfoot th:eq(2)').text(); // output: Total
Run Code Online (Sandbox Code Playgroud)

您可以根据需要使用.text().html() 。

要更新ththen 的值,请使用:

$('tfoot th#15').html($grandTotal);
Run Code Online (Sandbox Code Playgroud)

或者

$('tfoot th#15').text($grandTotal);
Run Code Online (Sandbox Code Playgroud)

注意不要仅使用数值作为id