鼠标事件(点击变颜色)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        #big {
            width: 200px;
            height: 200px;
            border: black 1px solid;
            background-color: pink;
        }
        
        #red {
            width: 20px;
            height: 20px;
            border: black 1px solid;
            background-color: red;
            margin: 10px;
            float: left;
        }
        
        #green {
            width: 20px;
            height: 20px;
            border: black 1px solid;
            background-color: green;
            margin: 10px;
            float: left;
        }
        
        #blue {
            width: 20px;
            height: 20px;
            border: black 1px solid;
            background-color: blue;
            margin: 10px;
            float: left;
        }
    </style>
</head>

<body>
    <div id="big">
        <div id="red" onclick="change('red')"></div>
        <div id="green" onclick="change('green')"></div>
        <div id="blue" onclick="change('blue')"></div>
    </div>
    <script type="text/javascript">
        function change(color) {
            var big = document.getElementById("big");
            big.style.backgroundColor = color
        }
    </script>
</body>

</html>

鼠标事件(点击变颜色)

上一篇:content:“\26A1“特殊字符和图标记录


下一篇:html原生js实现99乘法表