jQuery Custom [:] Expression

本文介绍了一个针对jQuery的选择器表达式扩展方法,通过增加自定义的选择器如`:submitable`和`:nothidden`来增强jQuery的功能,使得开发者能够更方便地筛选DOM元素。

 

core jQuery.expr[:] expresssions

animated=function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}


button=function(a){return "button"==a.type||jQuery.nodeName(a,"button");}


checkbox=function(a){return "checkbox"==a.type;}

 


checked=function(a){return a.checked;}


contains=function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;}


disabled=function(a){return a.disabled;}


empty=function(a){return !a.firstChild;}


enabled=function(a){return !a.disabled;}


eq=function(a,i,m){return m[3]-0==i;}


even=function(a,i){return i%2==0;}


file=function(a){return "file"==a.type;}


first-child=function(a){return a.parentNode.getElementsByTagName("*")[0]==a;}


first=function(a,i){return i==0;}


gt=function(a,i,m){return i>m[3]-0;}


has=function(a,i,m){return jQuery.find(m[3],a).length;}


header=function(a){return /h/d/i.test(a.nodeName);}


hidden=function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";}


image=function(a){return "image"==a.type;}


input=function(a){return /input|select|textarea|button/i.test(a.nodeName);}


last-child=function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;}


last=function(a,i,m,r){return i==r.length-1;}


lt=function(a,i,m){return inth=function(a,i,m){return m[3]-0==i;}


odd=function(a,i){return i%2;}


only-child=function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");}


parent=function(a){return a.firstChild;}


password=function(a){return "password"==a.type;}


radio=function(a){return "radio"==a.type;}


reset=function(a){return "reset"==a.type;}


selected=function(a){return a.selected||jQuery.attr(a,"selected");}


submit=function(a){return "submit"==a.type;}


text=function(a){return "text"==a.type;}


visible=function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";}

sample custom expresssions added to jQuery.expr[':']

 

the code

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值