<!DOCTYPE html>
<!--
点击变色
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#box{
width: 200px;
height: 100px;
background: black;
}
</style>
</head>
<body>
<div id="box"></div>
<script>
var i = true;
var box = document.getElementById("box");
box.onclick = function () {
if(i==true){
box.style.background="red";
i = false;
}else{
box.style.background="green";
i = true;
}
}
</script>
</body>
</html>