gpt4 book ai didi

javascript - jQuery 如何获取 td 单元格值

转载 作者:行者123 更新时间:2023-11-28 15:24:55 25 4
gpt4 key购买 nike

当用户单击行上的任意位置时,我试图获取发票编号的值

下面是我的表格

<div class="panel ui-widget-content" id="invoiceList">
<h2 class="ui-widget-header ui-corner-top" style="cursor: pointer; "><span>Invoices</span></h2>
<table cellspacing='0' id='header' class="ui-widget">
<tr>
<th>Invoice Number</th>
<th>Invoice Total</th>
</tr>
<tr>
<td><a href="#" >INV-Error_Test1</a></td>
<td>22.000000 USD</td>
</tr>
<tr>
<td><a href="#" >INV-Error_Test2</a></td>
<td>22.000000 USD</td>
</tr>
</table>
</div>

下面是我的 jQuery,仅当单击发票号码字段时才提供发票号码

$("#invoiceList td").click(function (e) {
var result = $(this).text();
console.log('invoice --->'+result);
});

http://jsfiddle.net/5n62md3m/

当用户点击该行的任意位置时,有人可以帮我获取发票号码吗?

最佳答案

检查一下,这可能是一个解决方案:

$('tbody tr').on('click', function(e){
var value = $(this).find('td:first-child a').text();
alert(value);
e.stopPropagation();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="panel ui-widget-content" id="invoiceList">
<h2 class="ui-widget-header ui-corner-top" style="cursor: pointer; "><span>Invoices</span></h2>
<table cellspacing='0' id='header' class="ui-widget">
<thead>
<tr>
<th>Invoice Number</th>
<th>Invoice Total</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="#" >INV-Error_Test1</a></td>
<td>22.000000 USD</td>
</tr>
<tr>
<td><a href="#" >INV-Error_Test2</a></td>
<td>22.000000 USD</td>
</tr>
</tbody>
</table>
</div>

关于javascript - jQuery 如何获取 td 单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29440451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com