Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery按ID获取tfoot th值_Jquery_Html_Html Table - Fatal编程技术网

使用jquery按ID获取tfoot th值

使用jquery按ID获取tfoot th值,jquery,html,html-table,Jquery,Html,Html Table,请看以下内容: <table border="0" id="npoGridView"> <thead> <tr> <th>Quantity Order</th> <th>Cost P.U</th> <th>Total</t

请看以下内容:

<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>
$('tfoot th:eq(0)').text(); // output: Quantity Order

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

$('tfoot th:eq(2)').text(); // output: Total

数量订单
成本单价
全部的
//TD。。。。。。。
数量订单
成本单价
全部的
我已经在tfoot中为th指定了id(即id=“15”),现在我想使用jquery获取th

如何使用jquery获取特定的th值表单页脚?

$(th\u id).text() 这将给出该特定dom元素的文本值

$('#npoGridView tfoot').each(function() {
  console.log($('th', this).text());
});
获取任何特定的
th
值,如
Total

您可以获得
th
的值,如下所示:

<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>
$('tfoot th:eq(0)').text(); // output: Quantity Order

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

$('tfoot th:eq(2)').text(); // output: Total
你可以根据需要使用或

要更新
th
的值,请使用:

$('tfoot th#15').html($grandTotal);

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

我会使用.html()

此外,请记住,ID不应以数字开头。

value get successfylly$('tfoot th#15').html('+$grandTotal+'');追加值,而不是覆盖。如何覆盖旧值?成功获取值$('tfoot th#15').html('+$grandTotal+'');追加值,而不是覆盖。如何覆盖旧值@Sanketvalue获得成功$('tfoot th#15').html('+$grandTotal+'');追加值,而不是覆盖。如何覆盖旧值?为什么要使用$('tfoot th#15').html(''+$grandTotal+'')$('tfoot th#15').html($grandTotal);应该这样做。。。
$('th#15').html();