cssquery()

cssQuery()

version 2.0.2

还在使用 getElementsByTagName? 哼~

简介

cssQuery() 是一款强大的 跨浏览器 JavaScript 脚本方法, 它能够利用“CSS 选择器”来 获取 DOM 文档。支持所有CSS1CSS2 以及部分 CSS3 选择器。

用法

语法
elements = cssQuery(selector [, from]);

其中 selector (必需的) 是一个有效的 CSS 选择器 ,而 from (可选的) 则是一个被 selector 筛选的文件、元素或队列。

方法为所需变量 (elements) 返回一个 JavaScript 队列。 如果没有与之匹配的, 则返回空队列。

下面是一些例子:

// find all paragraphs that are direct descendants//  of the document bodyvar tags = cssQuery("body > p");// find all elements with the "href" attributevar tags = cssQuery("[href]");// find all anchor elements with "href" equal to "#"var tags = cssQuery("a[href='#']");// find all images contained by the above anchorsvar images = cssQuery("img", tags);// find all listsvar tags = cssQuery("dl,ol,ul");// query an external xml documentvar tags = cssQuery("my|:root>my|link", myXMLDoc);// just plain complicatedvar complex = "p>a:first-child+input[type=text]~span";var tags = cssQuery(complex);
支持的选择器
  • *
  • E
  • E F
  • 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"]

兼容性

已知可运行于以下平台:

  • Microsoft Internet Explorer 5+ (Windows)
  • Microsoft Internet Explorer 5.2 (Mac)
  • Firefox/Mozilla 1.6+
  • Opera 7+
  • Netscape 6+
  • Safari 1.2

源代码

下载

您可以在这里 下载 cssQuery. 压缩包中包含源代码和 测试页面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值