我想要一個星級評分系統,請檢查JSFiddle。我想堅持鼠標點擊評分。Jquery的星級評分
HTML:
<div class="rating-star rating-star-off" data-value="0"></div>
<div class="rating-star rating-star-off" data-value="1"></div>
<div class="rating-star rating-star-off" data-value="2"></div>
<div class="rating-star rating-star-off" data-value="3"></div>
<div class="rating-star rating-star-off" data-value="4"></div>
</div>
CSS:
.rating-star{width:25px;height:25px;float:left;margin-right:5px;}
.rating-star-off{background:#eee url(star-off.svg) no-repeat;}
.rating-star-on{background:#000 url(star-on.svg) no-repeat;}
的jQuery:
$(function(){
$(".rating-star").click(function(e){
$(this).prevAll().andSelf().addClass('rating-star-on');
$(this).nextAll().removeClass('rating-star-on');
});
$(".rating-star").hover(function(){
$(this).prevAll().andSelf().addClass('rating-star-on');
$(this).nextAll().removeClass('rating-star-on');
});
$(".rating-star").mouseout(function(){
$(".rating-star").removeClass('rating-star-on');
});
});
http://jsfiddle.net/piyush_dezi/a67gv2o7/
在此先感謝您的幫助。
問題或問題是? – charlietfl
添加簡單的if else語句點擊鼠標 –