html:
<div class="star-cell" id="clickStar">
<img src="../img/star.png"><img src="../img/star.png">
<img src="../img/star.png">
<img src="../img/star.png">
<img src="../img/star.png">
</div>
js:
$('#clickStar').on('click','img',function(){
var curr=$(this).index();
var imgList=$('#clickStar img');
console.log(imgList.length);
for(var i=0; i<imgList.length;i++){
var tempImg=imgList[i];
if( i <= curr){
tempImg.src='../img/starA.png';
}else{
tempImg.src='../img/star.png';
}
}
})
<div id="QuacorGrading" >
<strong>评分</strong>
<input name="1" type="button" />
<input name="2" type="button" />
<input name="3" type="button" />
<input name="4" type="button" />
<input name="5" type="button" />
<input name="6" type="button" />
<input name="7" type="button" />
<input name="8" type="button" />
<input name="9" type="button" />
<input name="10" type="button" />
<span id="QuacorGradingValue"><b><font size="5" color="#fd7d28">6.5</font></b>分</span>
</div><!--QuacorGrading end-->
<script type="text/javascript">
var GradList = document.getElementById("QuacorGrading").getElementsByTagName("input");
for(var di=0;di<parseInt(document.getElementById("QuacorGradingValue").getElementsByTagName("font")[0].innerHTML);di++){
GradList[di].style.backgroundPosition = 'left center';
}
//图片上面有个图标,分别是高亮显示,不是高亮显示,通过设置backgroundPotion来设置它们的显示位置
for(var i=0;i < GradList.length;i++){
GradList[i].onmouseover = function(){
for(var Qi=0;Qi<GradList.length;Qi++){
GradList[Qi].style.backgroundPosition = 'right center';//全部设置为不亮的颜色
}
for(var Qii=0;Qii<this.name;Qii++){
GradList[Qii].style.backgroundPosition = 'left center';//小于器name值的元素 都设置为高亮状态
}
document.getElementById("QuacorGradingValue").innerHTML = '<b><font size="5" color="#fd7d28">'+this.name+'</font></b>分';
}
}
</script>