请教大神,这个代码为啥要按两下按钮后才能正常变色,要是后面再用个else if就正常了
<!doctype html>
<html>
<head>
<style>
div {
width:500px;
height:300px;
background-color:red;}
</style>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<div id="box"></div>
<input type="button" value="按钮" onClick="bianse()" />
<script>
function bianse(){
var x=document.getElementById("box");
if(x.style.backgroundColor=="red"){
x.style.backgroundColor="blue";
}else{
x.style.backgroundColor="red";
}
}
</script>
</body>
</html>