美文网首页
实现星星评分(仅展示)

实现星星评分(仅展示)

作者: 前端新阳 | 来源:发表于2019-12-13 15:29 被阅读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)  //'★★★★★'
    

    相关文章

      网友评论

          本文标题:实现星星评分(仅展示)

          本文链接:https://www.haomeiwen.com/subject/igvfnctx.html