简体   繁体   English

有没有简单的方法可以使用JQuery Mobile动态切换主题?

[英]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.

相关问题 使用jQuery在内容之间切换的简单方法 - Easy way to switch between content with jquery jQuery mobile-将选择菜单动态切换到多个 - jQuery mobile - dynamically switch Select Menu to Multiple 有什么简单的方法可以检测到attr jquery - is there is any easy way to detect attr jquery 如何使用SASS动态切换颜色主题? - How to dynamically switch color themes using SASS? 有什么简单的方法可以写这个吗? - Is there any easy way to write this? 什么是在jQuery UI和jQuery Mobile之间切换的最佳方式 - What's the best way to switch between jQuery UI and jQuery Mobile 有什么方法可以销毁行动装置上的magiczoomplus-javascript / jquery - is there any way to destroy magiczoomplus on mobile - javascript/jquery 如何在列表视图中过滤内部子元素以及使用Jquery在移动应用程序中将按字母顺序滚动条添加到列表视图的任何简便方法 - How to filter Inner child elements in List view & also any easy way to Add Alphabetical Scroll Bar to List View in an Mobile App Using Jquery 用Java设置Jquery UI Mobile导航栏状态的任何方法吗? - Any way to set Jquery UI Mobile navbar status with Javascript? 使用jQuery时,是否有任何简单的方法来获取DOM后代(例如parents()方法)? - Is there any easy way to get DOM descendants like with the parents() method when using jQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM