我是靠谱客的博主 典雅冰淇淋,这篇文章主要介绍关于jquery $.expr[':'],现在分享给大家,希望可以做个参考。

学习JQuery时 遇到一组代码

jQuery.expr[':'].data = function(a, i, m){
...
};

对这个$.expr[':'] 实在没搞懂是啥,四处搜寻了一下,找到一些相关解释:

If you need a reusable filter to target specific elements based on their characteristics, you can extend jQuery’s selector expressions under the jQuery.expr[':'] object; this is an alias for Sizzle.selectors.filters. Each new filter expression is defined as a property of this object。意思为:如果你需要一个可重用的过滤器来根据它们的特性来定位特定的元素,你可以在jQuery.expr [':']对象下扩展jQuery的选择器表达式;这是Sizzle.selectors.filters的别名。每个新的过滤器表达式都被定义为这个对象的属性。

实际上说白了就是自定义伪类选择器 类似于

jQuery.expr[':'].between = function(a, i, m){
var tmp=m[3].split(".");
return tmp[0]-0<i&&i<tmp[1]-0;
};

定义了一个between选择器。

另外,想要同时添加多个新选择器,最好使用jQuery的extend()方法

jQuery.extend(jQuery.expr[':'], {
data1 : function(){
},
data2 : function(){
},
data3 : function(){
},
}); 

最后

以上就是典雅冰淇淋最近收集整理的关于关于jquery $.expr[':']的全部内容,更多相关关于jquery内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(138)

评论列表共有 0 条评论

立即
投稿
返回
顶部