欢迎来到福编程网,本站提供各种互联网专业知识!

cssQuery()的下载与使用方法

发布时间:2007-01-12 作者: 来源:转载
IntroductioncssQuery()isapowerfulcross-browserJavaScriptfunctionthatenablesqueryingofaDOMdocumentusingCSSselectors.AllCSS1andCSS2selectorsareallowedplusquiteafewCSS3selectors.UsageSyntaxelements=cssQuery(selector[,fr
Introduction
cssQuery()isapowerfulcross-browserJavaScriptfunctionthatenablesqueryingofaDOMdocumentusingCSSselectors.AllCSS1andCSS2selectorsareallowedplusquiteafewCSS3selectors.

Usage
Syntax
elements=cssQuery(selector[,from]);whereselector(required)isavalidCSSselectorandfrom(optional)isadocument,elementorarrayofelementswhichisfilteredbyselector.

ThefunctionreturnsaJavaScriptarrayofelements.Ifthereisnomatch,anemptyarrayisreturned.

Someexamples:

//findallparagraphsthataredirectdescendants//ofthedocumentbodyvartags=cssQuery("body>p");//findallelementswiththe"href"attributevartags=cssQuery("[href]");//findallanchorelementswith"href"equalto"#"vartags=cssQuery("a[href='#']");//findallimagescontainedbytheaboveanchorsvarimages=cssQuery("img",tags);//findalllistsvartags=cssQuery("dl,ol,ul");//queryanexternalxmldocumentvartags=cssQuery("my|:root>my|link",myXMLDoc);//justplaincomplicatedvarcomplex="p>a:first-child+input[type=text]~span";vartags=cssQuery(complex);AllowedSelectors
*
E
EF
E>F
E+F
E~F
E.warning
E#myid
E:link
E:first-child
E:last-child
E:nth-child(n)
E:nth-last-child(n)
E:only-child
E:root
E:lang(fr)
E:target
E:enabled
E:disabled
E:checked
E:contains("foo")
E:not(s)
E[foo]
E[foo="bar"]
E[foo~="bar"]
E[foo^="bar"]
E[foo$="bar"]
E[foo*="bar"]
E[foo|="bar"]
Compatibility
Knowntoworkonthefollowingplatforms:

MicrosoftInternetExplorer5+(Windows)
MicrosoftInternetExplorer5.2(Mac)
Firefox/Mozilla1.6+
Opera7+
Netscape6+
Safari1.2

Source Code

cssQuery.js cssQuery-level2.js cssQuery-level3.js cssQuery-standard.js

相关推荐