<script> //假设后台返回的数量为3 var arr = [false, false, false, false, false] arr.splice(0, 3) console.log(arr) //[false,false] for (var i = 0; i < 3; i++) { arr.unshift(true) } console.log(arr, '输出最后一个') // [true, true, true, false, false] </script>
如果用vue或者是avalon,最好直接在html中去判断,其中
el.score表示的是返回数,然后根据三元表达式去选取class。。。。能用html的千万别用js,麻烦!!!!
<p style="display: inline-block;"> <span ms-class="['fishqc-report-xing-small',el.score >=1 ?'fishqc-report-xing-active':'fishqc-report-xing' ]"></span> <span ms-class="['fishqc-report-xing-small',el.score >=2 ?'fishqc-report-xing-active':'fishqc-report-xing' ]"></span> <span ms-class="['fishqc-report-xing-small',el.score >=3 ?'fishqc-report-xing-active':'fishqc-report-xing' ]"></span> <span ms-class="['fishqc-report-xing-small',el.score >=4 ?'fishqc-report-xing-active':'fishqc-report-xing' ]"></span> <span ms-class="['fishqc-report-xing-small',el.score >=5 ?'fishqc-report-xing-active':'fishqc-report-xing' ]"></span> </p>