English 中文(简体)
根据表格浏览量本身的状况,用jquery绘制表格的不同行数
原标题:Coloring different rows of a table using jquery based on condition in the table rows itself
  • 时间:2012-01-13 07:55:03
  •  标签:
  • jquery

I am working on improving the visual appeal of table rows. The data in table rows is generated dynamically and has lots of information. There is a column in that table which gives the time when that particular information row was issued. On the basis of the days/months etc before which the information was issued, I have to color the different rows.

It s exactly like as shown in the following link : http://www.nseindia.com/live_market/dynaContent/live_watch/equities_stock_watch.htm

此外,表层还必须有小块彩色的酒吧,其中的颜色将由同一行的另一领域确定。 我很想知道如何在 j忙中做到这一点。 我知道javascript,但听起来。

任何类型的帮助都将受到赞赏。

感谢。

问题回答

例如,根据价值,你可以改变桌子的颜色(固定电池价值减去零):

// 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 ==

为了接上囚室的囚室,可使用

// 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


Next alternative is to walk over all trs:

$( 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 );
        }
    });
});

http://jsfiddle.net/pk3tB/3/“rel=“nofollow”>example


使用<代码>.find(“td.<selector>”;;<selector>必须是td的一类。 也可使用<代码>.find(“td[attr= .]”,以过滤带有特殊特性的所有<代码>tds。 但是,我不知道内容选择。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签