码迷,mamicode.com
首页 > 其他好文 > 详细

用点击事件做红绿灯2

时间:2019-06-03 22:18:05      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:tail   button   toggle   nts   style   idt   sum   doc   script   

点击事件红绿灯

<!doctype html>
<html lang=zh>
<head>
    <meta charset="UTF-8">
    <title>红绿灯</title>
    <style>
        .c1 {
            width: 400px;
            height: 400px;
            border-radius: 50%;
            border: 3px solid black;
        }
        .bg_red {
            background-color: red;
        }
        .bg_green {
            background-color: green;
        }
    </style>
</head>
<body>
<div class="c1   bg_red bg_green"></div>
<button id = 'b1'> change color </button>



<script >
let b1Ele = document.getElementById('b1');
b1Ele.onclick = function () {
    let dEle = document.getElementsByClassName('c1')[0];
    dEle.classList.toggle('bg_green');
    };


</script>
</body>
</html>

用点击事件做红绿灯2

标签:tail   button   toggle   nts   style   idt   sum   doc   script   

原文地址:https://www.cnblogs.com/ruhai/p/10969820.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!