[英]Is there any easy way to switch themes dynamically with JQuery Mobile?
Like the question says, is there some way I can go about switching themes in JQuery Mobile dynamically. 就像问题所说,有什么方法可以动态地在JQuery Mobile中切换主题。 I just upgraded to beta 1 today and thought it would be cool if the user could pick there own theme if they want.
我今天刚刚升级到beta 1,并认为如果用户可以根据需要选择自己的主题会很酷。 I haven't seen anything in the documentation to do this specifically, but certainly there is some way to go about it, if someone could just point me in the right direction.
我没有在文档中看到任何具体的内容,但当然有一些方法可以解决它,如果有人可以指出我正确的方向。
Hardly sure, but it looks to me like jQuery Mobile's demo has a little theme switcher right inside it. 很难肯定,但它看起来像jQuery Mobile的演示在其中有一个小主题切换器。 Looks like this is the code that calls it:
看起来这是调用它的代码:
$("#someElement").bind("vclick", function() {
$.themeswitcher();
});
You can find the theme switcher's code right here . 你可以在这里找到主题切换器的代码。
Didn't mess around with it, but this sure looks like what you're talking about. 没有搞乱它,但这肯定看起来像你在说什么。
I use a dropdown to allow my users to choose a theme. 我使用下拉列表允许我的用户选择主题。 Here is the code I use for that:
这是我用于的代码:
function changeTheme() {
var theme = $("#ddlTheme :selected").val();
var cssUrl = 'css/themes/' + theme + '/jquery-ui-1.8.13.custom.css';
var themeStyle = $("#theme-style");
themeStyle.attr({
rel: "stylesheet",
type: "text/css",
href: cssUrl
});
}
Create a <link>
tag with the id "theme-style". 创建一个id为“theme-style”的
<link>
标签。 Make it point to your default link. 指向您的默认链接。
I use theme roller to create my themes and add them to a sub directory under my css/themes directory named for the theme it represents. 我使用主题滚轮来创建我的主题,并将它们添加到我的css / themes目录下的子目录中,该目录以它所代表的主题命名。 I place this value in the dropdown to display to the users.
我将此值放在下拉列表中以显示给用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.