百度首页 | 百度空间
 
查看文章
 
YUI增加CSS选择器
2007年12月06日 星期四 下午 02:58
最近在YUI的2.4更新上终于看到了CSS选择器,很先进的,虽然这是在jQuery Prototype之后实现,但是,也是很好的,可以这样写
var elements = YAHOO.util.Selector.query("#content p.hello");

query

static Array query ( selector , root , firstOnly )
Retrieves a set of nodes based on a given CSS selector.
Parameters:
selector <string> The CSS Selector to test the node against.
root <HTMLElement | String> optional An id or HTMLElement to start the query from. Defaults to Selector.document.
firstOnly <Boolean> optional Whether or not to return only the first match.
Returns: Array
An array of nodes that match the given selector.
支持3个参数,第二个就是选择器的顶元素,第三个就是是否值返回第一个匹配,但是dustin在blog中表示希望加入第4个参数,就是不需要2次循环就能实现each功能,这样
var collection = Select.query("#example p > span[lang^=us]", null, null,
function(el) {
// do stuff with 'el'
}
);
等下版本,虽然我不使用YUI
 

类别:javascript&web2.0 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码:
 

     

©2008 Baidu