gpt4 book ai didi

jquery - jQuery .not 选择器可以与 .delegate 一起使用吗?

转载 作者:行者123 更新时间:2023-12-01 00:43:54 25 4
gpt4 key购买 nike

我正在尝试对所有 <a> 进行 Ajax 调用id #filter 内的元素没有类 .noAjax不知何故我无法让它工作。有人可以看一下我的语法吗?

$("#filter").not($("a.noAjax")).delegate("ul#portfolio-list li a", "click", function() {
if ($.browser.msie) {
location.hash = "#/" + this.pathname;
} else {
location.hash = this.pathname;
}
return false;
});

当我尝试只使用a时或a.ajax (当然我在尝试之前添加了它)作为 .delegate 的选择器根本不起作用。使用上面的 jquery,ajax 可以工作,但即使我单击 a.noAjax 的链接,它也会尝试加载内容

最佳答案

使用:not()选择器:

$("#filter").delegate("ul#portfolio-list li a:not(.noAjax)","click",function() {
if ($.browser.msie) {
location.hash = "#/" + this.pathname;
} else {
location.hash = this.pathname;
}
return false;
});

或者您可以委托(delegate)给 ul 元素,因为它使用唯一的 ID,以提高选择器性能:

$("#portfolio-list").delegate("li a:not(.noAjax)", ...);

关于jquery - jQuery .not 选择器可以与 .delegate 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4216306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com