效果:
代码实现:
params.forEach(v => {
const {
marker,
seriesName
value,
data: {
rate,
id
}
} = v
var res = rate //rate为 '30%'
res = res.substr(0, res.length - 1)
var color = Number(res) > 0 ? "num" : "num1"
str += `<div class="chart-suggests">
<div>
<span class="car-name">${ marker } ${ seriesName }</span>
<span class="chain">${units(value)} 环比 </span>
<span class="percentage ${color}">${rate} </span>
<span class="car-model" onclick="clickHandle(id)">钻去车款</span>
</div>
</div>`
})
注意:写入标签的使用,不要直接写 color,要写成 ${color},是变量!!!
如果 percentage选择器 里面写了字体颜色,那么 color 里面的颜色不会生效!!!