我的表格行中有 2 个按钮。一个“开始”按钮和一个“完成”按钮。现在我正在使用此代码来运行 AJAX 调用。
$(document).ready(function(){
$(document).on("click", "button", function(){
rowID = "row" + this.id;
$("#" + rowID).load("eventHandlersPHP/updateStart.php", {
roomID: this.id
});
});
$(document).on("click", "button", function(){
rowID = "row" + this.id;
$("#" + rowID).load("eventHandlersPHP/updateComplete.php", {
roomID: this.id
});
});
});
现在我的代码不知道要抓取哪个按钮,只是随机选择要运行的代码。 如何仅选择该行中的第一个按钮或第二个按钮并仍然将其绑定(bind)。
最佳答案
更改您的选择器:
$('button:nth-child(1)').click(function(){
...
})
$('button:nth-child(2)').click(function(){
...
})
或用户javascript调用html代码上的点击事件:
在 HTML 中:
<button onclick="fun1()">btn1</button>
在 JavaScript 中:
function fun1(){
...
}
关于javascript - 使用 Jquery 选择正确的绑定(bind)按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44504692/