当按下特定按钮(在本例中为接受按钮)时,我将如何触发按钮单击事件。
我试过以下几种方法,但收效甚微:
Javascript
$('.notification-expand .Request .active-item > .accept-button').click(function () {
alert("hello");
});<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>小提琴在这里
发布于 2015-03-08 13:34:58
选择器中有错误,应该如下所示:
$('.notification-expand.Request.active-item .accept-button').click(function () {
alert("hello");
});发布于 2015-03-08 13:35:37
您需要连接所有没有空格的类,以捕获目标按钮。
$('button.accept-button', '.notification-expand.Request.active-item').click(function () {
alert("hello");
});请参阅更新后的片段
注意".className1.className2"的语法而不是".className1 .className2"
发布于 2015-03-08 13:30:54
应该是这样的:
$('button.accept-button').click(function(){ ... });如果这是整个代码的话,就没有必要把整个列表写下来了。
编辑--编辑--
因此,当有更多的项目,但只有一个活动(我猜),然后只针对活动项类:
$('div.active-item button.accept-button').click(function(){ ... });https://stackoverflow.com/questions/28926958
复制相似问题