0
点赞
收藏
分享

微信扫一扫

js---操作星星

汤姆torn 2022-02-19 阅读 96
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <script src="js/jquery-1.8.3.min.js"></script>
</head>
<body>
<div>
    <span>☆</span>
    <span>☆</span>
    <span>☆</span>
    <span>☆</span>
    <span>☆</span>
</div>
<script>
    $(function () {
        $("span").on({
            "mouseover":function () {
                var index = $(this).index();
                $("span:lt("+(index+1)+")").text("★");
            }, "mouseout":function () {
                var index = $(this).index();
                $("span:lt("+(index+1)+")").text("☆");
            },"click":function () {
                var index = $(this).index();
                $("span:lt("+(index+1)+")").text("★");
                $("span").off();
            }
        })
    })
</script>
</body>
</html>

效果图;

 

举报

相关推荐

0 条评论