以下 用的发if 语句 改变 box 的颜色 示例如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>相加</title>
<style type="text/css">
.box{
width:300px;
height:400px;
}
</style>
<script type="text/javascript">
window.onload=function(){
var vat=document.getElementById("btn");
var Ccolor=document.getElementById("box1");
// alert(Ccolor.style.backgroundColor)
vat.onclick=function(){
if (Ccolor.style.backgroundColor=="gold"){
Ccolor.style.backgroundColor="red";
}
else if(Ccolor.style.backgroundColor=="red"){
Ccolor.style.backgroundColor="pink";
}
else{
Ccolor.style.backgroundColor="gold";
}
}
}
</script>
</head>
<body>
<div id="box1" class="box" style="background-color:gold" ></div>
<input type="button" id="btn" value="改变颜色">
</body>
</html>