五星好评
三星好评
HTML
<div class="wrapper">
<span class="active">♥</span>
<span>♥</span>
<span>♥</span>
<span>♥</span>
<span>♥</span>
</div>
CSS
<style>
.active{
color: red;
}
</style>
JS
<script>
let _spans=document.querySelectorAll("span");
[..._spans].forEach((_span,index)=>{
_span.onclick=function(){
for(let i=0;i<_spans.length;i++){
if(i<=index){
_spans[i].className='active';
}else{
_spans[i].className='';
}
}
}
})
</script>