【问题标题】:jQuery mobile how to apply a single button theme to all buttonsjQuery mobile 如何将单个按钮主题应用于所有按钮
【发布时间】:2012-12-18 20:52:39
【问题描述】:

我希望我所有的 (data-role="button") 的主题都是 (data-theme="b") 浅蓝色..

我知道编写 jQuery 的人不会认真地浪费生命重复输入数千次。那么它是否像定义了 .css 属性一样应用,我只需要将它放在我的标题中或将另一个 .js 文件链接到它?

在 CSS 中,我知道它看起来像 .button { data-theme: b; } 一样简单。聪明的人通过在一个地方完成需要一遍又一遍地重复的任务来节省时间。

但在 jquery 中,它似乎总是写成..

<div data-role="navbar">
    <ul>
        <li><a href="#home" data-role="button" data-icon="home" data-theme="b">Home</a></li>
        <li><a href="#" data-role="button"data-icon="arrow-r" data-theme="b">Blog</a></li>
        <li><a href="#videos" data-role="button" data-icon="arrow-r" data-theme="b">Videos</a></li>
        <li><a href="#photos" data-role="button" data-icon="arrow-r" data-theme="b">Photos</a></li>
        <li><a href="#tweets" data-role="button" data-icon="arrow-r" data-theme="b">Tweets</a></li>
    </ul>
</div>

有没有办法解决这个问题,还是将其保留为默认主题更聪明?

【问题讨论】:

  • 您不只是使用属性选择器 (a[data-role="button"] { ... }) 使用 CSS 对其进行样式设置有什么特别的原因吗?

标签: jquery css mobile button


【解决方案1】:

您应该能够使用结合了&lt;a&gt; 标记和button 属性的JQuery 选择器来实现这一点。

$("a[data-role='button']").attr("data-theme","b");

编辑

显然,刷新 JQuery Mobile 主题可能有点棘手。 It's be asked on SO a few times; here's some info. from the JQM FAQ.

【讨论】:

  • 附带说明,有什么方法可以在文档准备好之前应用此主题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多