问题描述
我正在尝试对id #filter
中没有类.noAjax
的所有<a>
元素进行Ajax调用,以某种方式我无法使其正常工作.有人可以看看我的语法吗?
I'm trying to make an Ajax call on all <a>
elements inside the id #filter
which don't have the class .noAjax
and somehow i can't get it to work. could someone have a look at my syntax please?
$("#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
的选择器时,什么都没有.与上面的ajax jQuery一起工作,但即使我单击带有a.noAjax
when i try to just use a
or a.ajax
(which i of course added before trying) as the selector for .delegate
nothing works at all. with the jquery above the ajax works, but it tries to load content even when i click a link with a.noAjax
推荐答案
使用 :not()
选择器代替:
Use the :not()
selector instead:
$("#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;
});
或者您也可以委托给ul
元素,因为它使用唯一的ID,以提高选择器的性能:
Or you could delegate to the ul
element instead, since it's using a unique ID, for improved selector performance:
$("#portfolio-list").delegate("li a:not(.noAjax)", ...);
这篇关于jQuery .not选择器是否可以与.delegate一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!