标签: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>
标签:tail button toggle nts style idt sum doc script
原文地址:https://www.cnblogs.com/ruhai/p/10969820.html