此實例只能實現簡單的0-5整數值打分
直接po代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<style>
body { font-size: 30px; }
#star { color: orange; }
</style>
</head>
<body>
<p>4分</p>
<div id="star"></div>
<script src="./jquery-3.1.1.min.js"></script>
<script>
var num = 4;
var str = "★★★★★☆☆☆☆☆".slice(5 - num, 10 - num);
$("#star").html(str);
</script>
</body>
</html>
結果圖: