您编写了哪些有用的自定义jQuery选择器? [英] What useful custom jQuery selectors have you written?

查看:76
本文介绍了您编写了哪些有用的自定义jQuery选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说,jQuery最好但尚未充分利用的功能之一是自定义选择器。我有一个相当简单的例子,挑出所有空的文本框:

For me, one of the best, yet under-utilised feature of jQuery is the custom selector. I have a fairly trivial example of this, to pick out all text boxes that are empty:

$(document).ready(function() {
    $.extend($.expr[':'], {
        textboxEmpty: function(el) {
            var $el = $(el);
            return ($el.val() == "") && ($el.attr("type") == "text");
        }
    });
});

并致电:

alert($(":textboxEmpty").length);

我真的想知道,如果其他人有他们写过的自定义选择器的一些有用的例子。

I was wondering, really, if anyone else had some useful examples of custom selectors they have written.

我当然不会对这些陷阱视而不见,并意识到它们可能很慢,因此应该与其他更快的选择器结合使用。听听我们是否应该注意其他任何问题会很有用。

I am, of course, not blind to the pitfalls of these, and realise that they can be quite slow and, as such, should be combined with other faster selectors. It would be useful to hear if there are any other problems we should be aware of.

推荐答案

我还没有写过,但 James Padolsey 精彩集合(用于视图中的元素,用于外部链接,用于具有特定 .data 财产等)

I haven't written any, yet James Padolsey has a great collection of selector plug-ins (for elements in view, for external links, for elements with a specific .data property, etc)

这篇关于您编写了哪些有用的自定义jQuery选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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