当按下特定按钮(在本例中为接受按钮)时,如何触发按钮单击事件。
我尝试了以下方法,但收效甚微:
Javascript
$('.notification-expand .Request .active-item > .accept-button').click(function () {
alert("hello");
});
HTML
<div class="notification-expand Request active-item" style="display: block;">
<div class="notification-body"></div>
<br>
<p>
<button type="button" class="btn btn-success accept-button btn-sm">Accept</button>
</p>
<div class="row">
<div class="col-xs-6 expand-col">
<button type="button" class="btn btn-warning barter-button btn-sm">Barter</button>
</div>
<div class="col-xs-6 expand-col">
<button type="button" class="btn btn-danger reject-button btn-sm">Reject</button>
</div>
</div>
</div>
最佳答案
您的选择器有错误,它应该如下所示:
$('.notification-expand.Request.active-item .accept-button').click(function () {
alert("hello");
});
关于javascript - 当元素上有多个类时触发按钮单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28926958/