jq实现星星评价

本文介绍了一款基于HTML5、CSS和JavaScript实现的星星评价插件,通过灵活的样式和交互设计,用户可以轻松地在网页上实现产品或服务的星级评价功能。插件支持动态显示评价等级文字,如'非常差'到'非常好',并能够响应用户的点击事件,自动调整已选星星的数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考:

https://www.jianshu.com/p/02969846f1ed

https://www.cnblogs.com/baixuemin/p/6492257.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="js/wyrem.js"></script>
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery-1.9.1.min.js"></script>
    <title>填写评价</title>
</head>
<style>
/* 星星评价打分 */
.star_box{
    margin: 0.1rem;
    background: #fff;
    height: 2rem;
    border-radius: 0.1rem;
}
.star_box p{
    font-size: 0.2rem;
    color: #231815;
    text-align: center;
    font-weight: bold;
    line-height: 1rem;
}
.appr_start{
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
}
.appr_start span{
    width: 0.6rem;
    height: 0.54rem;
    background: url(../images/icon_star.png) no-repeat center;
    background-size: 100% 100%;
    margin-right: 0.24rem;
}
.appr_start span.on{
    background: url(../images/icon_astar.png) no-repeat center;
    background-size: 100% 100%;
}
.appr_start em{
    font-size: 0.24rem;
    color: #666666;
}
</style>
<body style="background: #eeefef">
    <div class="star_box">
        <p>星级评价</p>
        <div class="appr_start">
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            <em></em>
        </div>
    </div>

    <script type="text/javascript">
    //星星评分
    $(function() {       // 小星星     
        $(".appr_start span").click(function() {        
            $(this).addClass("on");        
            $(this).prevAll().addClass("on");        
            $(this).nextAll().removeClass("on");        
            var sta_index = $(this).index();        
            if(sta_index == 0) {          
                $(this).siblings("em").html('非常差');        
            } else if(sta_index == 1) {          
                $(this).siblings("em").html('差');        
            } else if(sta_index == 2) {          
                $(this).siblings("em").html('一般');        
            } else if(sta_index == 3) {          
                $(this).siblings("em").html('好');        
            } else if(sta_index == 4) {          
                $(this).siblings("em").html('非常好');        
            }      
        })    
    })

</script>

</body>
</html> 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值