实现星星评分(仅展示)

2019-12-13  本文已影响0人  前端新阳

参考: https://hotwhy.github.io/2018/09/10/%E5%8F%A6%E7%B1%BB%E5%AE%9E%E7%8E%B0%E6%98%9F%E6%98%9F%E8%AF%84%E5%88%86%EF%BC%88%E4%BB%85%E5%B1%95%E7%A4%BA%EF%BC%89/

代码:

let 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)  //'★★★★★'
上一篇下一篇

猜你喜欢

热点阅读