<万博manbetx平台> 一个DOM选择器-万博manbetx平台

一个DOM选择器

从一个js文件中分离出来的,还不知道作者是谁。

在指定的DOM节点context下按CSS2,CSS3选择器的定义去找出相关的DOM节点
支持的选择器:
E[att^=”val”],E[att$=”val”],E[att*=”val”],E[att~=”val”],E[att|=”val”],E[att!=”val”],E[att=”val”]
E:enabled,E:disabled,E:checked,E:not(s)
+ E.class
> E.class
E.class
E#id
E
参数:pattern:CSS2 Selector可以通过逗号分隔多个选择器,context指定要查找的DOM节点范围
返回值:[DOM Collection]

[code=”javascript”]

function selector(pattern, context) {
?var re = new RegExp(‘([a-z]*)([\.#:]*)(.*|$)’, ‘ig’);
?var match = re.exec(pattern);
?//alert(context);
?var conditions = [];?
?if (match[2] == ‘#’)?conditions.push([‘id’, match[3]]);
?else if(match[2] == ‘.’)?conditions.push([‘className’, match[3]]);
?else if(match[2] == ‘:’)?conditions.push([‘type’, match[3]]);?
?var s = match[3].replace(/\[(.*)\]/g,’$1′).split(‘@’);
?for(var i=0; i

赞(0) 打赏
未经允许不得转载:万博manbetx平台 » 一个DOM选择器

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #-49

    您测试过没 很大的BUG 没改过代码暂时取不到对象的

    aspic9年前 (2009-11-11)回复

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏