大神们帮忙看看,
<!DOCTYPE html>
<html>
<head>
<title>测试</title>
<meta charset = "utf-8">
<style>
div {width:150px;height:150px;display: inline-block;}
.on {-webkit-animation:move 0.5s;}
@-webkit-keyframes move {
from{transform: rotate(0deg);}
to {transform: rotate(60deg);}
}
</style>
</head>
<body>
<div style = "background-color:red;"></div>
<div style = "background-color:green;"></div>
<div style = "background-color:blue;"></div>
<div style = "background-color:yellow;"></div>
<div style = "background-color:gray;"></div>
<script type="text/javascript">
var divBox = document.getElementsByTagName("div");
alert(divBox);
for(var i = 0;i<divBox.length;i++){
divBox[i].addEventListener("mouseover",function(){
if(divBox[i].classList.contains("on")==true){ //这个地方提示错误。。。。
this.classList.remove("on");
}else{
this.className = "on";
}
})
}
</script>
</body>
</html>
classList.contains
本身不会报错,但是有兼容性要求。IE10+。还有就是你那个判断根本不需要
==true