jQuery .not选择器是否可以与.delegate一起使用? [英] Does the jQuery .not selector work with .delegate?

查看:192
本文介绍了jQuery .not选择器是否可以与.delegate一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对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;
});

当我尝试仅使用aa.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一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆