Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to implement the function for a User to change style of the application.

Index.html

<!DOCTYPE html>
<html>
    <head>
        <link id="style" rel="stylesheet" type="text/css" href="red-stylesheet.css" />
    </head>
</html>

Javascript

function swapStyle(sheet) {
    document.getElementById('style').setAttribute('href', sheet);
}

Where sheet = either blue-stylesheet.css or red-stylesheet.css.

It doesn't seem to work. My default theme is red, but when trying to change to blue, ALL styling seems to just disappear, and I can't get the red theme back.

How does one proceed?

(PhoneJS/DevExtreme application)

Default when app is initiated

enter image description here

After pressing "Blue"

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
206 views
Welcome To Ask or Share your Answers For Others

1 Answer

Hope this helps :

$('head>link[type="text/css"]').attr('href',sheet);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...