如果有一个这样的表..更改文本颜色(如果,否则)
<table>
<tr>
<td class="cell1">20</td>
</tr>
</table>
等one..with多个<td>
当然..
现在我想改变文字的<td>
的颜色,如果数量大于5
smaler这是可能使用jQuery?
<td>
没有输入字段或段落,只是文本。
如果有一个这样的表..更改文本颜色(如果,否则)
<table>
<tr>
<td class="cell1">20</td>
</tr>
</table>
等one..with多个<td>
当然..
现在我想改变文字的<td>
的颜色,如果数量大于5
smaler这是可能使用jQuery?
<td>
没有输入字段或段落,只是文本。
$('.cell1').each(function(i, n) {
if($(n).text() < 5) $(n).css('color', 'green');
});
迭代通过每个单元,校验值,然后相应地改变
编辑我的链接评论到的jsfiddle – 2012-03-27 16:40:01
尼斯,非常感谢:)) – 2012-03-27 16:49:14
@AndrewJackson你可能想在此有一个读http://meta.stackexchange.com/questions/5234/how-does-accepting-an -answer-work :) – 2012-03-27 17:43:47
这应该工作:
$("table.myTable td").each(function(){
if(parseInt($(this).html())<5){
$(this).addClass("newColor");
}
});
可以测试领域的这样的内容:
$('.cell1').each(function() {
if($(this).text() < 5) {
$(this).css('color', 'red');
}
});
你所说的 “如果该数字小于5” 是什么意思?你的意思是TD中的20个,还是你的意思是cell1类中的1个?或者你是指TD事件的数量? – afrederick 2012-03-27 16:39:06