代码链接在这里 - http://jsfiddle.net/V5g2m/
var $template = $('div.main');
$template.off('change.filterIt', 'select.filter')
.on('change.filterIt', 'select.filter', function(){
alert(1);
});
$template.off('change', 'select.filter[name="source"]')
.on('change.getNewSource', 'select.filter[name="source"]', function(){
alert(2);
});
任何人都可以帮我解决我的问题 - 如何仅从该选择器 select.filter[name="source"] 取消事件 change.filterIt 的绑定(bind)。它应该保留在其他 select.filter 元素上,但不会在当前元素上触发。
最佳答案
在添加事件之前使用 :not()
将其过滤掉
var $template = $('div.main');
$template.off('change.filterIt', 'select.filter')
.on('change.filterIt', 'select.filter:not([name="source"])', function(){
alert(1);
});
$template.off('change', 'select.filter[name="source"]')
.on('change.getNewSource', 'select.filter[name="source"]', function(){
alert(2);
});
关于jquery - 如何使用不同的选择器进行 .off() 和 .on() 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21982282/