这是我的html表。
<table id="status_table" class="table table-bordered">
<tr>
<th>S.No</th>
<th>PRODUCT NO.</th>
<th>DESCRIPTION</th>
<th>QTY</th>
<th>SCOPE</th>
<th>AMOUNT</th>
<th>GST %</th>
<th>GST AMOUNT</th>
<th>FINAL AMOUNT</th>
<th>VENDOR ID</th>
<th>Delivery Date</th>
<th>Submited Date</th>
<th>Status</th>
</tr>
</table>
这里我从json附加表数据
$("#status_table > tbody").append(
"<tr><td id='sno'>"
+ sno
+ "</td><td id='product_id'>"
+ obj.status[i].productno
+ "</td><td id='description'>"
+ obj.status[i].description
+ "</td><td id='qty'>"
+ obj.status[i].qty
+ "</td><td id='scope'><a href='#'>view scope</a></td><td id='amount'>"
+ obj.status[i].amount
+ "</td><td id='gstp'>"
+ obj.status[i].gst_p
+ "</td><td id='gstamount'>"
+ obj.status[i].gst_amount
+ "</td><td id='finalamount'>"
+ obj.status[i].final_amount
+ "</td><td id='vendor_id'>"
+ obj.status[i].vendor_id
+ "</td><td id='ddate'>"
+ obj.status[i].delivery_date
+ "</td><td id='date'>"
+ obj.status[i].date
+ "</td><td id='status'>"
+ status
+ "</td></tr>");
我需要为(范围)特定列执行onclick。在这里,我无法获得细胞柱。
答案 0 :(得分:1)
试试这个
$("#status_table > tbody").append("<tr class="use-address"><td id='sno' >" + sno + "</td><td id='product_id'>" + obj.status[i].productno + "</td><td id='description'>" + obj.status[i].description + "</td><td id='qty'>" + obj.status[i].qty + "</td><td id='scope'><a href='#'>view scope</a></td><td id='amount'>" + obj.status[i].amount + "</td><td id='gstp'>" + obj.status[i].gst_p + "</td><td id='gstamount'>" + obj.status[i].gst_amount + "</td><td id='finalamount'>" + obj.status[i].final_amount + "</td><td id='vendor_id'>" + obj.status[i].vendor_id + "</td><td id='ddate'>" + obj.status[i].delivery_date + "</td><td id='date'>" + obj.status[i].date + "</td><td id='status'>" + status + "</td></tr>");
$(".use-address").click(function () {
var $row = $(this).closest("tr"); // Find the row
var $tds = $row.find("td");
$.each($tds, function () {
alert($(this).text());
console.log($(this).text());
});
});
答案 1 :(得分:0)
你没有&#34;&lt; tbody&gt;&#34;在你的代码中。请尝试以下
<table id="status_table" class="table table-bordered">
<tbody>
<tr>
<th>S.No</th>
<th>PRODUCT NO.</th>
<th>DESCRIPTION</th>
<th>QTY</th>
<th>SCOPE</th>
<th>AMOUNT</th>
<th>GST %</th>
<th>GST AMOUNT</th>
<th>FINAL AMOUNT</th>
<th>VENDOR ID</th>
<th>Delivery Date</th>
<th>Submited Date</th>
<th>Status</th>
</tr>
</tbody>
</table>