Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.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
Javascript 如何在点击tr的td';s元素?_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 如何在点击tr的td';s元素?

Javascript 如何在点击tr的td';s元素?,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有一个tr专栏,像这样。那么,在单击具有id“quick Update order product”的更新之后,如何使用jquery获取tr的id 您可以使用: $('td a').click(function(){ alert($(this).closest('tr').attr('id')); }); 首先,如果重复此行,则应在按钮上使用类,而不是id,因为重复的id属性无效 <tr id="product-id-<?=$product->product->i

我有一个tr专栏,像这样。那么,在单击具有id“quick Update order product”的更新之后,如何使用jquery获取tr的id

您可以使用:

$('td a').click(function(){
  alert($(this).closest('tr').attr('id'));
});

首先,如果重复此行,则应在按钮上使用类,而不是
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>
用这个


您是否有单击处理程序。。。如果是这样,请签出
在单击具有id的更新“快速更新订单产品”之后,如何使用jquery获取tr的id
为什么要使用prop而不是attr?@RoryMcCrossan谢谢你,它确实有效。也谢谢你的建议:)@AnilChaudhari很乐意帮忙
<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>
$('.quick-update-order-product').click(function() {
    var trId = $(this).closest('tr').prop('id');
});
$('.quick-update-order-product').click(function() {
    var trId = $(this).closest('tr').attr('id');
});