<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.star-off {
height: 19px;
width: 19px;
display: inline-block;
background: url("images/stare.png") no-repeat;
background-position: -39px 0;
}
.star-on {
height: 19px;
width: 19px;
display: inline-block;
background: url("images/stare.png") no-repeat;
background-position: -2px 0;
}
</style>
<script>
window.onload = function () {
var aB = document.getElementsByTagName('b');
for (var i = 0; i < aB.length; i++) {
aB[i].onmouseover = function () {
aB[i].className = 'star-on';
}
}
}
</script>
</head>
<body>
<div id="commit">
<span>总体评价:</span>
<span class="star">
<b class="star-off"></b>
<b class="star-off"></b>
<b class="star-off"></b>
<b class="star-off"></b>
<b class="star-off"></b>
</span>
<span id="text"></span>
</div>
</body>
</html>请问28行为什么报错啊
1 回答
已采纳

冥oo冥
TA贡献8条经验 获得超1个赞
在function函数里不识别aB[i],改用this吧
var aB = document.getElementsByTagName('b');
for (var i = 0; i < aB.length; i++) {
aB[i].onmouseover = function () {
this.className = 'star-on';
}
}
简单的说,
for(var i=0;i<10;i++){
a.onmouseover = b;
}
function b(){
//这儿不识别i
}
添加回答
举报
0/150
提交
取消