など。あなたは、値(ゼロ少ないし、テーブルセルの値)に応じて、テーブルセルの背景色を変更することができます。
// for each table cell
$('td').each(function() {
// get table cell value and try to convert to an float
var fValue = parseFloat($(this).text());
// if value is a number and less then zero
if (!isNaN(fValue) && fValue < 0) {
// change the background color to red
$(this).css('background-color', 'red');
}
});
スクリプトは、テーブルが構築された後に呼び出されることがあります。このexampleも参照してください。
=== === UPDATE
セルの行を取得するには、.parent()を使用することができます。
// for each table cell
$('td').each(function() {
// get table cell value and try to convert to an float
var fValue = parseFloat($(this).text());
// if value is a number and less then zero
if (!isNaN(fValue) && fValue < 0) {
// get table row
var oTableRow = $(this).parent();
// change the background color to red
oTableRow.css('background-color', 'red');
}
});
はまた、このexampleを参照してください。
次の代替すべてtr
秒以上歩くことです:
$('tr').each(function() {
var jRow = $(this);
// for each table cell
jRow.find('td').each(function() {
// get table cell value and try to convert to an float
var fValue = parseFloat($(this).text());
// if value is a number and less then zero
if (!isNaN(fValue) && fValue < 0) {
// change the background color of the row to red
jRow.css('background-color', 'red');
}
});
});
このexampleを参照してください。
.find("td.<selector>")
<selector>
がtd
のクラスである必要があります使用するには。代わりに.find("td[attr='..']")
を使用して、td
のすべてを特殊属性でフィルタリングすることができます。しかし、私はコンテンツのセレクタを知らない。
問題は 'td'ではなく' tr'をループし、 'find(" td。 ")' ... –
で条件値を持つセルにアクセスすることをお勧めします私は私の答えを更新しました。 – scessor
素晴らしい!それは詳細な答えです:-)私は最後の解決策が尋ねられたものから最も近いと思います... –