使用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();