简体   繁体   English

如何在YUI中做多个选择器

[英]How to do multiple selectors in YUI

How can i do multiples selectors in yui (yui 2) like in jquery : 我如何像jQuery中那样在yui(yui 2)中做倍数选择器:

$('h1, h2, el1, el2, .content, .title').css('color', 'red');

How can this one be written in yui (without doing YAHOO.util.Dom.addClass on each element seperately) 如何用yui编写这个代码(不对每个元素分别执行YAHOO.util.Dom.addClass)

Some of the DOM methods of YUI accept an array of elements to act on, and the addStlye() method is one of them, so you should be able to do: YUI的某些DOM方法接受要操作的元素数组,而addStlye()方法就是其中之一,因此您应该能够执行以下操作:

YAHOO.util.Dom.setStyle(['el1', 'el2'], 'color', 'red');

Think it only works with ids though, so the first element should have an id of el1, etc... 认为它仅适用于id,因此第一个元素的id应该为el1,依此类推...

EDIT: 编辑:

You can also use the YAHOO.util.Selector module to query the DOM and return the array of elements to pass to setStyle() , eg: 您还可以使用YAHOO.util.Selector模块来查询DOM并返回要传递给setStyle()的元素数组,例如:

var els = YAHOO.util.Selector.query('h1, h2, h3, .some-element');

YAHOO.util.Dom.setStyle(els, 'color', 'red');

或在YUI 3中:

Y.all('h1, h2, h3, .content, .title').setStyle('color', 'red');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM