简体   繁体   English

从jQuery Mobile更改默认数据主题

[英]Change the default data-theme from jQuery Mobile

With jQuery Mobile I can create a page using a custom theme 使用jQuery Mobile,我可以使用自定义主题创建页面

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

Now this works, but requires that I add this line in each of my pages and every-time I add a new page. 现在这可行,但要求我在每个页面中添加此行,并且每次添加新页面。 I tried adding data-theme="s" to the body tag but this has no affect. 我尝试将data-theme="s"到body标签,但这没有任何影响。 Is there any way to do this other then setting it manually per page? 有没有办法做到这一点,然后每页手动设置?

You would have to do it programmatically, AFAIK. 你必须以编程方式,AFAIK。

Something along the lines of: 有点像:

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

Now, since there is no centralized hook - you will have to do the similar line for all theme options there are: 现在,由于没有集中式挂钩 - 您必须为所有主题选项执行类似的行:

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

and so on. 等等。

I don't have a list of all of them, but a quick look through the jquery.mobile-1.0rc1.js searching for .prototype.options. 我没有所有这些列表,但快速查看jquery.mobile-1.0rc1.js搜索.prototype.options. reveals these: 揭示这些:

$.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

so it seems to me that you can go with these and discover more as you go. 所以在我看来,你可以随身携带这些,并在你去的时候发现更多。 Note that not all of them are created like that - some are constructed dynamically in the code. 请注意 ,并非所有这些都是这样创建的 - 有些是在代码中动态构造的。 Look for Theme string to see what I mean. 寻找Theme字符串,看看我的意思。

Update 更新

$.mobile.page.prototype.options.theme should be updated as well - based on Moak's comment below. $.mobile.page.prototype.options.theme应该更新 - 基于Moak的评论如下。

The following worked for me. 以下对我有用。 Just make sure it's called after JQM is initialized. 只需确保在JQM初始化后调用它。

$.mobile.page.prototype.options.theme = "b";

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

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