javascript - 通过委托(delegate)在jquery中的选定div上应用点击功能

标签 javascript jquery

添加 Not of jquery 相反的最好方法是什么?

<div class="line-item">
<div class="thumb">
    Image goes here
</div>
<div class="title">
    Title goes here
</div>
<div class="destroy">
    Destroy Button goes here
</div>

这是 Java 脚本

$('div.line-item').delegate('div:not(".destroy")', 'click', function() {
alert('hi');
})

我想要的是在具有 .destroy 类的 div 上应用“点击”

这是工作演示: http://jsfiddle.net/trVKF/110/

最佳答案

使用更新版本的 jQuery 并执行以下操作:

$('div.line-item').on('click', '.destroy', function() {
//    ^^ static parent | ^^ event | ^^ dynamic element bound to handler
    alert('hi');
});

关于javascript - 通过委托(delegate)在jquery中的选定div上应用点击功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20496929/

相关文章:

javascript - 将一个元素悬停在另一个元素上

javascript - 我如何将分钟舍入到 momentjs 中最接近的 5 分钟标记?

javascript - 如何检查对 jQuery DataTable 的 ajax 调用是否已返回数据

javascript - 加载所有 requirejs 模块后运行操作

javascript - 如何根据不同的数组将数组的值更改为另一个值?

页面加载时jquery弹出窗口不会被蜘蛛索引

javascript - 如何将事件与生成的动态数据绑定(bind)

javascript - 将对象值作为单独的项目插入数组

javascript - 使用 js 或 jquery 单击工具栏按钮后包裹 html 标签

javascript - 单击取消并确定,在 js 中的删除确认中执行相同的操作