change jquery mobile color swatch dynamically

后端 未结 7 1095
隐瞒了意图╮
隐瞒了意图╮ 2020-12-17 18:13

I want to change a jquery-mobile buttons color swatch dynamically with javascript, but I can\'t\' find a way (except removing and adding all classes and event handlers, but

7条回答
  •  时光说笑
    2020-12-17 18:48

    I use this and it works perfectly !! :D

    Mikael Kindborg answer from Change data-theme in jQuery mobile

    $.mobile.changeGlobalTheme = function(theme)
        {
            // These themes will be cleared, add more
            // swatch letters as needed.
            var themes = " a b c d e";
    
            // Updates the theme for all elements that match the
            // CSS selector with the specified theme class.
            function setTheme(cssSelector, themeClass, theme)
            {
                $(cssSelector)
                        .removeClass(themes.split(" ").join(" " + themeClass + "-"))
                        .addClass(themeClass + "-" + theme)
                        .attr("data-theme", theme);
            }
    
            // Add more selectors/theme classes as needed.
            setTheme(".ui-mobile-viewport", "ui-overlay", theme);
            setTheme("[data-role='page']", "ui-page-theme", theme);
            setTheme("[data-role='header']", "ui-bar", theme);
            setTheme("[data-role='listview'] > li", "ui-bar", theme);
            setTheme(".ui-btn", "ui-btn-up", theme);
            setTheme(".ui-btn", "ui-btn-hover", theme);
        };
    

提交回复
热议问题