<div class="box" id="box"></div>
<button onclick="myfunction()">按钮</button>
<script>
function myfunction() {
var box = document.getElementById("box");
if (box.style.backgroundColor="aqua")
{
box.style.backgroundColor="red";
}
else {
box.style.backgroundColor="black";
}
}
</script>
1<br>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1276/viewspace-3140552/ ,如需转载,请注明出处,否则将追究法律责任。