gpt4 book ai didi

javascript - 如何在jquery中找到点击按钮的行号?

转载 作者:行者123 更新时间:2023-11-30 10:08:09 25 4
gpt4 key购买 nike

我有一个表,其中最后一列中有一个名为问题的按钮。在每一行中,当我单击按钮时,我希望它调用一个从服务器获取特定值的 ajax 函数。来自服务器的值将根据所选的行而有所不同。我目前的代码如下

var $dntb = $("#dntb");
$dntb.on("focusin", function() {
var i //have to get the row where the button is clicked
$("#iss" + i).click(function(event) {
var sditmId = $("#sditm").val();
var sdhedId = $("#sdhed").val();
$.get('getstock', {
sditmId: sditmId,
sdhedId: sdhedId
}, function(response) {
$("#stk").val(response);
});
});
});

请告诉我如何在上面的代码中找到'i'的值,如果这是错误的请告诉我正确的方法

表格如下

<table class="table table-bordered table-striped table-hover" id="dntb">
<thead>
<th><strong>Sales Order Number</strong></th>
<th><strong>Reference Order</strong></th>
<th><strong>Order Item</strong></th>
<th><strong>Quantity</strong></th>
<th><strong>Transport Time</strong></th>
<th><strong>Mode of Shipment</strong></th>
<th><strong>Delivery Date</strong></th>
<th><strong>Actions</strong></th>
</thead>
<jsp:useBean id="gen" scope="request" class="Common.General"/>
<tbody>
<c:set var="i" value="0"/>
<c:forEach items="${dlv.allDeliveryDetails}" var="row">
<tr>
<td>${row.sdhedIdDn}</td>
<td>${row.sdhedDn}</td>
<td>${row.sditmDn} - ${row.prdDn}</td>
<td>${row.qtyDn}</td>
<td>${row.trntmDn}</td>
<td>${row.mshDn}</td>
<td>${row.datDn}</td>
<td>
<button type="button" class="btn btn-default btn-sm btn-primary" data-toggle="modal" data-target="#myModal" onclick="setData('${row.sdconDn}', '${row.sdhedIdDn}', '${row.sditmDn}', '${row.sdconIdDn}')" id="iss">
<span class="glyphicon glyphicon-download"></span> Issue
</button>
</td>
</tr>
<c:set var="i" value="${i+1}"/>
</c:forEach>
</tbody>
<tfoot>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tfoot>
</table>

最佳答案

这可能会帮助你交配.. :)

注:Jquery版本>=1.7

$('body').on('click', 'button', function(event) {
var rowindex = $(this).closest('tr').index();
console.debug('Index', rowindex);
});

仅供引用

index()

关于javascript - 如何在jquery中找到点击按钮的行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28067302/

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