Html 在Jquery中获取特定的表行数据
我有一张这样的桌子:Html 在Jquery中获取特定的表行数据,html,jquery,Html,Jquery,我有一张这样的桌子: <table class="datatable" id="datatable"> <thead> <tr> <th>ID</th> <th>Shopfront Product ID</th> <th>Shopfront Product Name</th>
<table class="datatable" id="datatable">
<thead>
<tr>
<th>ID</th>
<th>Shopfront Product ID</th>
<th>Shopfront Product Name</th>
<th>Quantity</th>
<th>Base Price</th>
<th>Special Price</th>
<th>Start Date</th>
<th>End Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>11EA8E6B-346F-00B2-BCFE-023831B74848</td>
<td>Heineken Lager Sleek 330ml Can 24pk</td>
<td>1</td>
<td>2.99</td>
<td>1.99</td>
<td></td>
<td></td>
<td>
<button class="accept-btn">Accept</button>
</td>
</tr>
<tr>
<td>2</td>
<td>11EA8E6B-346F-00B2-BCFE-023831B74848</td>
<td>Heineken Lager Sleek 330ml Can 24pk</td>
<td>6</td>
<td>15.00</td>
<td>13.99</td>
<td>2020-05-31 00:00:00</td>
<td>2020-06-12 00:00:00</td>
<td>
<button class="accept-btn">Accept</button>
</td>
</tr>
<tr>
<td>3</td>
<td>11EA8E6B-346F-00B2-BCFE-023831B74848</td>
<td>Heineken Lager Sleek 330ml Can 24pk</td>
<td>24</td>
<td>37.00</td>
<td>35.00</td>
<td></td>
<td>2020-06-12 00:00:00</td>
<td>
<button class="accept-btn">Accept</button>
</td>
</tr>
</tbody>
</table>
但它给我所有点击行的列数据。我怎样才能像我期望的那样得到具体的专栏
非常感谢您需要在不使用的情况下使用textval。首先。另外,将数据标签属性添加到每个td元素也很好。它有助于将所有数据序列化到一个对象:
$(“.accept btn”)。单击(函数(){
让数据={};
$(this).closest('tr').find('td[数据标签]).each(函数(){
数据[$(this).data('label')]=$(this.text();
});
控制台日志(数据);
});代码>
身份证件
店面产品标识
店面商品名称
量
底价
特价
开始日期
结束日期
行动
1.
11EA8E6B-346F-00B2-BCFE-023831B74848
喜力啤酒圆滑330ml罐装24pk
1.
2.99
1.99
接受
2.
11EA8E6B-346F-00B2-BCFE-023831B74848
喜力啤酒圆滑330ml罐装24pk
6.
15
13.99
2020-05-31 00:00:00
2020-06-12 00:00:00
接受
3.
11EA8E6B-346F-00B2-BCFE-023831B74848
喜力啤酒圆滑330ml罐装24pk
24
37
35
2020-06-12 00:00:00
接受
$(".accept-btn").click(function() {
$(this).closest('tr').find('td').each(function() {
var textval = $(this).text();
console.log(textval.first);
});
});