浏览 495 次
|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2007-12-06
最近在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
声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
| 返回顶楼 | |
|
时间:2007-12-06
前缀太长了
YAHOO.util.Selector.query
这也是我不太喜欢yui的一个原因。太严肃了。
|
|
| 返回顶楼 | |
|
时间:2007-12-06
你可以这样
var Y = YAHOO.util,
Select = Y.Selector,
Dom = Y.Dom;
var collection = Select.query("#example p > span[lang^=us]");
Dom.batch(collection, function(el) {
// do stuff with 'el'...
});dustin写的,当然其他库也可以这样。namespace长不使问题在js当中。
|
|
| 返回顶楼 | |




