【发布时间】:2017-10-26 10:14:14
【问题描述】:
好的,所以,我的代码:
HTML:
<div id ="close"></div>
<div id="mask">
<div id="picture">
<div id="prev"></div>
<img src="" />
<div id="next"></div>
</div>
</div>
#picture 里面的所有东西都是由 jquery html() 添加的,所以我需要 on() (delegate) 来为这些元素添加一些功能。
jQuery:
$('#close, #mask').on("click", function(){
closeImg();
});
$('#picture').on("click", '#prevImg', function(){
prevImg();
});
$('#fixed').on("click", '#nextImg', function(){
nextImg();
});
如果我点击#nextImg/#prevImg 函数 closeImg() 也会被调用。而且我不会。如何从 #nextImg/#prevImg 中删除处理程序 closeImg() 但让调用 nextImg()/prevImg()?我想,我应该使用 off(),但我不明白怎么做,也找不到类似的例子。我的全部努力都失败了。
【问题讨论】: