为了账号安全,请及时绑定邮箱和手机立即绑定

新手​实现五星评价问题

新手​实现五星评价问题

慕九州7009252 2016-12-08 19:45:17
<!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

}


查看完整回答
反对 回复 2016-12-08
  • 1 回答
  • 0 关注
  • 889 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号