有关JS的一个小问题,请教大神
<!DOCTYPE html>
<html>
<head>
<title>事件添加</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/3.css" />
<script type="text/javascript">
function fun(){
this.style.backgroundColor="yellow";
alert(this.className);
this.style.backgroundColor="";
}
window.onload=function(){
var divs=document.querySelectorAll("div");
for(var i=0;i<divs.length;i++){
divs[i].addEventListener("click",fun,false);
}
}
</script>
</head>
<body>
<div class="d1">
<div class="d2">
<div class="d3">
</div>
</div>
</div>
</body>
</html>
这段代码里,this.style.backgroundColor="yellow"; 这一句效果出不来,为什么。