参考:
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>