<body>
<ul class="comment">
<li>☆</li>
<li>☆</li>
<li>☆</li>
<li>☆</li>
<li>☆</li>
</ul>
</body>
<script>
// 声明两个变量,分别记录实心和空心
var sx='★'
var kx='☆'
// 需求1
$('.comment>li').on('mouseenter',function(e){
$(this).text(sx).prevAll().text(sx)
$(this).nextAll().text(kx)
// console.log('this',this)
// console.log('e:',e)
// 出错
// $(this).text(sx).prevAll().text(sx).nextAll().text(kx)
}).on('mouseleave',function(){
// 需求2
$('.comment>li').text(kx)
// 获取点击的那个li
$('.comment>li[clickCurrent]').text(sx).prevAll().text(sx)
}).on('click',function(){
// 需求3
// 给当前鼠标点击的那个li添加一个属性,区别其他li
$(this).attr('clickCurrent','current').siblings().removeAttr('clickCurrent')
})
</script>
当鼠标扫过时,五角星变为实心,鼠标离开,五角星变为空心
最新推荐文章于 2023-06-05 11:45:00 发布