【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 herfh1>
    <p>this is the raido groupp>
    <div>
        <from>
            <input name="color" type="radio" onclick="change('red')" value="red">redinput>
            <input name="color" type="radio" onclick="change('green')" value="green">greeninput>
        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;

【javascript】修改css href_第1张图片

 

 【javascript】修改css href_第2张图片

 

转载于:https://www.cnblogs.com/cuphoria/p/11519995.html

你可能感兴趣的:(【javascript】修改css href)