我有一个有点击事件的 div。
<div id="e_tooth_pk1" class="e_tooth_pk1" title="Tooth 1">Tooth 1</div>
这里是JS:
$("#e_tooth_pk1").off("click");
$("#e_tooth_pk1").click(function() {
alert("hiii");
});
我尝试使用 off
来停止点击事件,但它触发了它。我认为缺少一些东西。
最佳答案
将事件设置为关闭状态后,您将再次绑定(bind)它。这就是问题所在。
尝试,
$("#e_tooth_pk1").click(function() {
alert("hiii");
});
$("#e_tooth_pk1").off("click");
但我想知道为什么你需要这种情况发生。我认为您正在寻找 .one()
功能。
DEMO
关于javascript - 即使使用 off 后 div 也会触发 click 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24014573/