我有一个tr专栏,就像这样。然后,在单击具有id“ quick-update-order-product”的“更新”后,如何使用jquery获取tr的ID?
<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属性无效。
<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
:
$('.quick-update-order-product').click(function() {
var trId = $(this).closest('tr').prop('id');
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句