function LightStar(num){ this.num=num; this.init() }LightStar.prototype={ init:function(){ this.lightOn(); this.bindEvent() }, bindEvent:function(){ var that=this; $("#a").on('mouseover','li',function(){ //这里的方法为什么不行呢???要在上面怎么修改才能调用的到呢 that.lightOn($(this).index()+1); //控制台输出的为underfined console.log(that.lightOn(2)) }).on('mouseout','li',function(){ that.lightOn(num); }).on('click','li',function(){ that.num=$(this).index()+1 }) }, lightOn:function(num){ var that=this; $("#a li").each(function(i,item){ if(i<that.num){ $(this).css('background-position','0 -32px') }else{ $(this).css('background-position','0 0') } }); },}; new LightStar(2)
添加回答
举报
0/150
提交
取消