1.说明
我们使用jQuery轻松选取一些元素进行修改样式,但有时候需要根据实际的内容去修改,比如说,根据一个表格内的单元格的文本内容判断修改显示的颜色,如果是异常的数据显示红色,正常的数据显示绿色
2.代码
function changeStatusColor() {
// 定位元素并且遍历
$(".node_status").each(function () {
// $(this)代表当前元素
if ($(this).text() == "正常") {
$(this).css({ "color": "green" })
} else if ($(this).text() == "良好") {
$(this).css({ "color": "yellow" })
} else if ($(this).text() == "滞后" || $(this).text() == "获取本地接口失败" || $(this).text() == "获取数据异常") {
$(this).css({ "color": "red" })
}
})
}