单击tr的td元素后如何获取tr的ID? [英] How to get id of tr after clicking its td's element?
本文介绍了单击tr的td元素后如何获取tr的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个tr列,像这样.然后,在单击具有id"quick-update-order-product"的更新后,如何使用jquery获取tr的ID?
I have a tr column, like this. Then how can I get the tr's id using jquery after clicking Update having id "quick-update-order-product"
<tr id="product-id-<?=$product->product->id;?>">
<td><span class="product_price_show"></span></td>
<td><span><?= $product->product_qty; ?></span></td>
<td><span><?= $product->product->stock->qty; ?></span></td>
<td><span><?= $product->total_price_tax_incl; ?></span></td>
<td>
<a class="quick-update-order-product">Update</a>
</td>
</tr>
先谢谢了..:)
推荐答案
首先,如果重复此行,则应在按钮上使用一个类,而不要使用id
,因为重复的id属性无效.
Firstly, if this row is repeated you should use a class on the button, not an id
, as duplicate id properties are invalid.
<tr id="product-id-<?=$product->product->id;?>">
<td><span class="product_price_show"></span></td>
<td><span><?= $product->product_qty; ?></span></td>
<td><span><?= $product->product->stock->qty; ?></span></td>
<td><span><?= $product->total_price_tax_incl; ?></span></td>
<td>
<a class="quick-update-order-product">Update</a>
</td>
</tr>
按钮上有课程后,您就可以使用closest()
查找tr
:
Once you've got the class on the button you can use closest()
to find the tr
:
$('.quick-update-order-product').click(function() {
var trId = $(this).closest('tr').prop('id');
});
这篇关于单击tr的td元素后如何获取tr的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文