Jquery 如何使用不同的选择器执行.off()和.on()操作

Jquery 如何使用不同的选择器执行.off()和.on()操作,jquery,Jquery,此处的代码链接- 有人能帮我解答我的问题吗?如何仅从该选择器中解除事件更改.filterIt的绑定select.filter[name=“source”]。它应该保留到其他选择。过滤元素,但不在当前触发。在添加事件之前,使用:not()过滤掉它 var $template = $('div.main'); $template.off('change.filterIt', 'select.filter') .on('change.filterIt', 'select.filter:not([na

此处的代码链接-


有人能帮我解答我的问题吗?如何仅从该选择器中解除事件更改.filterIt的绑定select.filter[name=“source”]。它应该保留到其他选择。过滤元素,但不在当前触发。

在添加事件之前,使用
: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);
});

“…但不触发当前”。您所说的“当前”是什么意思?选择.filter[name=“source”]是正确的,谢谢,但我想知道“如何解除绑定”,而不是“如何不绑定”。
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);
});