Dynamically changing theme

半城伤御伤魂 提交于 2019-12-25 05:19:06

问题


I am making an app with jQuery Mobile and PhoneGap. I want to dynamically chnge themes so I made somethinglike this:

function theme()
{
    Array.prototype.forEach.call(document.getElementsByTagName("*"), function (el) {
    el.setAttribute("data-theme", "e");
});
}

The problem is that themes change only after scrolling mouse on elements or for example on "tap" event.

How to fix it without reloading page? I want to set a theme and have it on all my sites, when they start.


回答1:


You can't in the way you're trying. When jQuery mobile looks at the data-theme attribute before the page is shown, it does its magic for you. That is, it changes the applied CSS rules based on the choosen theme. So, if you want to not reload the page, you have to change the css rules and not the data-theme attribute. Something like this:

$('#button1').css(....);


来源:https://stackoverflow.com/questions/12510043/dynamically-changing-theme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!