【javascript】修改css href

<!DOCTYPE html>
<html>

<head>
    <link href="./.css" rel="stylesheet" type="text/css" id="css">
    <script>
        function change(color) {
            let css = document.getElementById("css")
            if (color == "red") css.setAttribute("href", "./red.css")
            if (color == "green") css.setAttribute("href", "./green.css")
        }
    </script>
</head>

<body>
    <h1>change css by js herf</h1>
    <p>this is the raido group</p>
    <div>
        <from>
            <input name="color" type="radio" onclick="change('red')" value="red">red</input>
            <input name="color" type="radio" onclick="change('green')" value="green">green</input>
        </from>
    </div>
</body>

</html>
body {
    color: red;
}

h1 {
    text-decoration-line: 1px;
}

div {
    background-color: rgb(224, 71, 84);
    border: 1px dotted rgb(255, 191, 191);
}

//green
body {
    color: green;
}

h1 {
    text-decoration-line: 1px;
}

div {
    background-color: darkgreen;
    border: 1px dotted palegreen;

 

 

 

posted @ 2019-09-14 19:57  jm_epiphany  阅读(438)  评论(0编辑  收藏  举报