另类实现星星评分(仅展示),用于拓宽思路,实际并不怎么用得上:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25let stars = '★★★★★☆☆☆☆☆';
//一颗星
let rate1 = 1;
let star1 = stars.slice(5 - rate,10 - rate);
console.log(star1) //'★☆☆☆☆'
//两颗星
let rate2 = 2;
let star2 = stars.slice(5 - rate,10 - rate);
console.log(star2) //'★★☆☆☆'
//三颗星
let rate3 = 3;
let star3 = stars.slice(5 - rate,10 - rate);
console.log(star3) //'★★★☆☆'
//四颗星
let rate4 = 4;
let star4 = stars.slice(5 - rate,10 - rate);
console.log(star4) //'★★★★☆'
//五颗星
let rate5 = 5;
let star5 = stars.slice(5 - rate,10 - rate);
console.log(star5) //'★★★★★'