jquery 五星评价(图片实现)

≯℡__Kan透↙ 提交于 2020-03-12 16:38:00

1111

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>五星评价(图片实现) </title>
    <script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
    <div class="starMain" style="width: 100%;margin: 0 auto;height: 10px;line-height:10px;margin-top: 1px;">
        <img class="ev-star" src="/Script/image/evaluate/empty.png" />
        <img class="ev-star" src="/Script/image/evaluate/empty.png" />
        <img class="ev-star" src="/Script/image/evaluate/empty.png" />
        <img class="ev-star" src="/Script/image/evaluate/empty.png" />
        <img class="ev-star" src="/Script/image/evaluate/empty.png" />
    </div>
    <br/> <br />
    <input class="preData starResult" type="text" />

    <script>
        $(function () {
            $(".starMain").each(function () {
                starFun($(this));
            })
        });
        function starFun(element) {
            var imgs = element.find(".ev-star");
            var len = imgs.length;
            for (var i = 0; i < len; i++) {
                imgs[i].index = i;
                imgs[i].onclick = function () {
                    var count = 0;
                    for (var j = 0; j <= this.index; j++) {
                        imgs[j].src = "/Script/image/evaluate/full.png";
                        count++;
                    }
                    for (var h = (this.index + 1); h < len; h++) {
                        imgs[h].src = "/Script/image/evaluate/empty.png";
                    }
                    var starResult = $(this).parent().parent().find(".starResult");
                    starResult.val(count);
                }
            }
        }
    </script>
</body>
</html>

 五角星:实心五角星空心五角星

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!