Javascript 如何根据值的数量更改值的颜色?
我有这个HTML表和JSJavascript 如何根据值的数量更改值的颜色?,javascript,jquery,html,firebase,firebase-realtime-database,Javascript,Jquery,Html,Firebase,Firebase Realtime Database,我有这个HTML表和JS var-example=document.getElementid('*数值*'); var exampledbref=firebase.database().ref().child('example').child('value'); exampledbref.on('value' snap=>expample.innerText=snap.val()) 无标题文件 一串 一串 *数值* *数值* 检查值的jQuery解决方案是 jQuery // for eac
var-example=document.getElementid('*数值*');
var exampledbref=firebase.database().ref().child('example').child('value');
exampledbref.on('value'
snap=>expample.innerText=snap.val())代码>
无标题文件
一串
一串
*数值*
*数值*
检查值的jQuery解决方案是
jQuery
// for each <td>
$('td').each(function(){
// get the text value in each <td>
var val = $(this).text();
// convert to int
var int = parseInt(val);
// if more than 5
if(int > 5) {
$(this).css({'background': 'green'});
}else {
$(this).css({'background': 'red'});
}
});
//每个
$('td')。每个(函数(){
//获取每个文本中的文本值
var val=$(this.text();
//转换为整数
var int=parseInt(val);
//如果超过5
如果(int>5){
$(this.css({'background':'green'});
}否则{
$(this.css({'background':'red'});
}
});
一个简单的小提琴-你的代码是无效的,作为一个程序员,在转发代码之前检查代码是一个很好的做法。真正的代码有敏感的信息。我只需要一些“虚拟”的例子作为参考。它并不意味着被认真对待。无论你需要它作为你使用的参考,它都应该是有效的。