6

使用 jQuery Mobile,我可以使用自定义主题创建页面

<div data-role="page" data-theme="s" id="home">...

现在这可行,但要求我在每个页面中添加这一行,并且每次添加新页面时。我尝试添加data-theme="s"到正文标签,但这没有影响。除了每页手动设置之外,还有什么方法可以做到这一点?

4

2 回答 2

8

你必须以编程方式进行,AFAIK。

类似于以下内容:

$(document).bind( "mobileinit", function () 
{
    ...
    $.mobile.page.prototype.options.contentTheme = "z"; //your theme
    ...
});

现在,由于没有集中的钩子 - 您必须对所有主题选项执行类似的操作:

$.mobile.page.prototype.options.headerTheme
$.mobile.page.prototype.options.footerTheme

等等。

我没有所有这些的列表,但通过jquery.mobile-1.0rc1.js快速浏览搜索.prototype.options.揭示了这些:

$.mobile.page.prototype.options.backBtnTheme
$.mobile.page.prototype.options.headerTheme
$.mobile.page.prototype.options.footerTheme
$.mobile.page.prototype.options.contentTheme
$.mobile.listview.prototype.options.filterTheme

所以在我看来,你可以带着这些去发现更多。请注意,并非所有这些都是这样创建的——有些是在代码中动态构建的。查找Theme字符串以了解我的意思。

更新

$.mobile.page.prototype.options.theme也应该更新 - 基于下面 Moak 的评论。

于 2011-10-28T03:19:23.180 回答
1

以下对我有用。只需确保在 JQM 初始化后调用它即可。

$.mobile.page.prototype.options.theme = "b";
于 2014-02-24T00:16:40.523 回答