5星评级脚本

问题描述:

我正在写5星评级剧本,但他不能正常工作,当光标在星上他变了,但是当你走在其他星上时,前一颗星是不选择的,我需要所有星星去像正常评级系统一样一个一个选择。5星评级脚本

$('.fa-star-o').mouseover(function() { 
    $(this).removeClass('fa-star-o'); 
    $(this).addClass('fa-star'); 


}).mouseout(function() { 
    $(this).removeClass('fa-star'); 
    $(this).addClass('fa-star-o'); 
}); 


       <div class="companies-list-item-rating"> 
        <i class="fa fa-star-o"></i> 
        <i class="fa fa-star-o"></i> 
        <i class="fa fa-star-o"></i> 
        <i class="fa fa-star-o"></i> 
        <i class="fa fa-star-o"></i> 
        <span class="companies-list-item-rating-count">/ 53</span> 
       </div><!-- /.companies-list-item-rating --> 
      </div><!-- /.companies-list-item --> 
+0

你可以张贴此处的CSS –

您需要选择当前和以前的明星,并取消当前所有的明星之后跟随..

$('.fa-star-o').mouseover(function() { 
    $(this).addClass('fa-star'); 
    $(this).prevAll('.fa-star-o').addClass('fa-star'); 
    $(this).nextAll('.fa-star-o').removeClass('fa-star'); 
}).mouseout(function() { 
    $(this).parent().children('.fa-star-o').removeClass('fa-star'); 
}); 
+0

我希望我理解正确的类。 'fa-star'应该是启用的星星,'fa-star-o'是一个通用的星级。对吧? – Dropout

+0

仍然不起作用,这里是我的jsfiddle https://jsfiddle.net/8o4cL1o1/10/ – SkySonny

+0

你没有使用我在我的答案中提供的脚本,jQuery库链接在你的小提琴中缺失, fa-star-o'造型没有定义。我已经添加了一个临时样式来证明它的工作..看到https://jsfiddle.net/8o4cL1o1/11/ – Dropout