JavaScript--點擊顏色,爲主題更換背景顏色

鼠標點擊顏色塊,指定區域背景顏色更換

完整代碼:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        div, ul {
            margin: 0;
            padding: 0;
        }
        .first {
            height: 50px;
            /*outline: 1px solid red;*/
        }
        .second {
            height: 400px;
            outline: 1px solid gray;
        }
        #change {
            height: 370px;
        }
        .first>div {
            float: right;
            width: 30px;
            height: 30px;
            /*outline: 1px solid red;*/
            margin: 5px;
            margin-top: 9px;
        }
        .first>div:nth-child(1) {
            background-color: pink;
        }
        .first>div:nth-child(2) {
            background-color: blue;
        }
        .first>div:nth-child(3) {
            background-color: orange;
        }
        .second>div:first-child {
            height: 40px;
            /*outline: 1px solid red;*/
            background-color: gray;
        }
        ul {
            list-style-type: none;
        }
    </style>
</head>
<body>
    <div class="first">
        <div id="pink" οnclick="document.getElementById('change').style.backgroundColor='pink'"></div>
        <div id="blue" οnclick="document.getElementById('change').style.backgroundColor='blue'"></div>
        <div id="orange" οnclick="document.getElementById('change').style.backgroundColor='orange'"></div>
    </div>
    <div class="second">
        <div></div>
        <div id="change">
            <ul>
                <li>123</li>
                <li>456</li>
                <li>789</li>
                <li>123</li>
            </ul>
        </div>
    </div>
</body>
<script type="text/javascript">

</script>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章