|  | 
 
 发表于 2019-2-4 08:51:43
|
显示全部楼层 
| 这好今天早上一起来就写了一个超简单的评分,我用JQuery写的。现在看看真正的星级评分是怎么实现的。 
 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>五角星评分案例</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        .comment {
            font-size: 40px;
            color: rgb(206, 206, 0);
        }
        .comment li {
            float: left;
            cursor: pointer;
        }
        ul {
            list-style: none;
        }
    </style>
    <script src="jquery-1.12.2.js"></script>
    <script>
        $(function () {
            $('.comment>li').mouseover(function () {
                $(this).text('★').prevAll('li').text('★').end().nextAll('li').text('☆');
            }).mouseout(function () {
                $('.comment').find('li').text('☆');
                $('.comment>li[index=1]').text('★').prevAll('li').text('★');
            }).click(function () {
                // 自定义属性
                $(this).attr('index','1').siblings('li').removeAttr('index');
                // 
            });
        });
    </script>
</head>
<body>
<ul class="comment">
    <li>☆</li>
    <li>☆</li>
    <li>☆</li>
    <li>☆</li>
    <li>☆</li>
</ul>
</body>
</html>
 | 
 |