css - MooTools 1.1,如何获取类的 ID 并应用样式

标签 css mootools selector

我需要获取类的 id 属性并应用基于该 id 的样式。

例如,3 个列表项,每个都有“typo”类,一个 id 是“application”,另一个 id 是“application_osx”,最后一个 id 是“application_osx_terminal”

类“拼写错误”由 CSS 处理,但我需要根据 ID 名称分配背景图像。

因此,如果 id 恰好是“application_osx”或“somemotherid”,它会自动应用此 CSS

#application_osx { background: url(/path/to/image/application_osx.png) }
#someotherid { background: url(/path/to/image/someotherid.png) }

我正尝试为此使用 MooTools 1.1。

我猜它看起来像这个准系统

    <html>
    <head>
    <title>Blah</title>
    <script src="path/to/mootools.js"></script>
    <script>
    A SCRIPT THAT PRINTS OUT:
    #application_osx { background: url(/path/to/image/application_osx.png) }
    #someotherid { background: url(/path/to/image/someotherid.png) }
    BASED ON THE CLASS "TYPO"
    </script>
    </head>
    <body>
    <ul>
    <li id="application_osx" class="typo">Application OSX</li>
    <li id="someotherid" class="typo">Someotherid</li>
    </ul>
    </body>
    </html>

最佳答案

$$('.typo').each(函数(el){ el.setStyle('背景图像', 'url(/path/to/'+el.id+'.png)') });

如果我理解得很好,应该可以解决这个问题......

关于css - MooTools 1.1,如何获取类的 ID 并应用样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3462028/

相关文章:

javascript - 选择没有任何包含字符串的类的元素

iphone - 需要做与 NSSelectorFromString() 相反的事情

CSS :not selector element of another class

html - 为什么我的 float 列表元素堆叠?

html - 如何在表单中定位 div 类

javascript - 在初始页面加载时保持 MooTools Accordion 关闭

javascript - mootools |隐藏和显示动画

html - 如何切掉元素的一部分,但在 DOM 中保持可用?

javascript - 使用 Angular Material 展开折叠列表项

javascript - 寻找好的 Mootools Javascript 教程