Mootools 获得二级名称
我看到使用 jquery 获取第二类名称的方法,但如何在 mootools 中执行此操作,我的元素是
我需要匹配完整的类名称,如 li .parent.active 并调整高度(如果该类存在)我尝试过 $$('li').hasClass('parent active')
或 getProperty 但如果我添加 .parent.active 我明白
该表达式不是合法表达式。现在我必须支持mootols 1.1、1.2、1.3在CMS上工作,所以我从丑陋的1.1版本开始,
这就是实际需要的
var holderdiv =$('mymenu');
if($$('li.parent.active')){holderdiv.setStyle({'height':'50px'});
I see the method of getting second class name with jquery but how do I do it in mootools , my element is <li class="parent active">
I need to match full class name like li.parent.active and adjust height if that class is present I tried$$('li').hasClass('parent active')
or getProperty but all of them return true even if active is not present, if I add .parent.active I get
The expression is not a legal expression. now I must support mootols 1.1 ,1.2 ,1.3 working on CMS here so I started with the ugly one 1.1 version
this is how is actually needed
var holderdiv =$('mymenu');
if($('li.parent.active')){holderdiv.setStyle({'height':'50px'});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
if($$('li.parent.active') == true)
返回 true,它是 true(已定义,不为 null)。如果你的意思是说:是否至少有一个子元素具有 .parent 和 .active,你可以这样做:
如果它们不是holderdiv的子元素,只需执行
document.getElement
或whateverElObj。 getElement
相反。由于旧的 xpath 内容,这可能会在 1.11 中中断。
一种在所有版本中都有效的方法是这样的(尽管只有在 MooTools.version 由于性能成本而错误时才应该这样做)双循环):
.some
将遍历所有li.parent
,直到找到一个与条件匹配的(hasClass("active")) 然后返回布尔值 true否则,错误。
http://jsfiddle.net/dimitar/BqwAk/
如果您需要保留 lis 的引用到一个集合中,使用
.filter
代替:如果所有都有 .parent 并且只有一个可以处于活动状态,那么您并不真正关心,因此您可以执行
或
...来仔细检查它们是否不存在'都没有.父母。
if($$('li.parent.active') == true)
returns true as in, it's truthy (defined, not null).if you mean to say: is there at least one child element that has .parent and .active, you can do:
if they are not children of holderdiv just do
document.getElement
orwhateverElObj.getElement
instead.this will likely break in 1.11 due to old xpath stuff.
one way to do it so it works in all versions would be this (though you should only do this if MooTools.version is wrong due to performance cost of double loops):
the
.some
will run through allli.parent
until it finds one that matches the condition (hasClass("active")
) and then return boolean true else, false.http://jsfiddle.net/dimitar/BqwAk/
if you need to keep a reference of the lis into a collection, use
.filter
instead:if all have .parent and only one can be active, you don't really care so you can just do
or
... to double check if they don't all have .parent.
您可以简单地将所有元素与
parent
和active
类相匹配并设置它们的样式,MooTools 使这一切变得简单:You could simply match all elements with both classes
parent
andactive
and set their style, MooTools makes that easy: