switch theme in javascript -
I try to switch to my subjects ... but it does not work. I want a default style (when I open the page), and I want to switch from
, but I try it but it does not work:
< Code> & lt; Link rel = "stylesheet" type = "text / css" href = "script / easyi / theme / dark / easy types? V = 20130 9 13" />This is the topic for changing and changing:
and my switch:
& lt; Form action = "#" action = "post" & gt; & Lt; Select name = "select_box_chosen_color" id = "select_box_chosen_color" & gt; & Lt; Option value = "blue" & gt; Blue & lt; / Options & gt; & Lt; Option value = "orange" & gt; Yellow & lt; / Options & gt; & Lt; / Select & gt; & Lt; Input type = "submit" & gt; & Lt; / Form & gt;
option 1: a CSS file
value You need to use the jQuery
only for the
change on your
select , change the CSS class into body Tag
var theme = $ ('# select_box_chosen_color'); Theme.change (function () {$ (document.body) .prop ("class", $ (this) .find (": selected"). Val ());}) Change (); // Optional trigger ollods
In CSS, you use the theme chosen as a major class to overwrite the theme:
. MyDefault {color: green; } .blue. MyDefault {color: blue; }
Option 2: Multiple CSS files
Assume that you are developing on a
http: // server If you want to change the file, click on the
file: // system on the
link tag of the id or data attribute Use
HTML
& lt; Link id = "themeLink" href = "script / easy / theme / dark / easy types? V = 20130913" Rel = "stylesheet" type = "text / css" />
The options can hold directory structure.
& lt; ID = "Theme Options" & gt; & Lt; Option value = "" & gt; Default & lt; / Option & gt; & Lt; Option value = "blue" & gt; Blue & lt; / Options & gt; & Lt; / Select & gt; Depending on your directory structure, you should create a directory root related to your URL
/ . Insert with value from
JS and
select options will reload the most modern browser urls, if it Created correctly without problem.
var option = $ ('# Theme Options'), dir =' script / easyui / themes / ', file =' Easyui.css? V = ', link = $ (' #meamelink '); Options.change (function () {var selected = $ (this) .find (': selected'). Val (), time = new date (). GetTime (); // Optionally to avoid caching files Time includes = selected .length? '/' + File: file; link.prop ('href', dir + selected + file + time);}). Change (); // Alternate trigger load
I've heard some tools / browsers and combinations with
iframe did not reload the style properly. For this you should see a dynamic creation of a
link tag technology.
Wrap your script functionality inside a DOM ready event.
Comments
Post a Comment