使用jquery基于两列中的条件突出显示行

时间:2014-02-24 21:25:43

标签: javascript jquery html

我有一张这样的表:

S.No  Name  Year   Pay

 1      A   2004   100
 2      B   2005   200
 3      C   2004   75

需要突出显示年份= 2004 在{75,200,300}支付的行。我想用这样的东西:

$('tr').find('td:eq(2):contains(2004)')
  .parent()
    .find('td:eq(3)')
      .filter(function(){
        return parseInt($(this).text()) < 300;
      })
      .parent()
        .css('backgroundColor', '#E8E8E8'); 

在上面的工作jquery中,我需要替换内部条件&lt; 300 ,类似 {75,200,300}

请帮我调试这个问题。

2 个答案:

答案 0 :(得分:1)

如何使用正则表达式?如果

    $('tr').find('td:eq(2):contains(2004)').parent().find('td:eq(3)').filter(function(){
return parseInt($(this).text().match(/(75)|(200)|(300)/g));
}).parent().css('backgroundColor', '#E8E8E8'); 

我只是在同一个小提琴中做了另一种方式: http://jsfiddle.net/joeSaad/6jPs9/#base

答案 1 :(得分:0)

试试这个 Fiddle Demo

$('tr').filter(function() {
    var $this=$(this);
    // Search for 2004 and trim whitespace just in case in 3th column (year)
    if ($.trim($this.children('td').eq(2).text()) == "2004") {
        // Search for predefined values in 4th column and if found return true
        if ( ~['75', '200', '300'].indexOf( $.trim($this.children('td').eq(3).text()) ) ) {
            return true;
        }
        return false;
    }
    return false;
}).css('backgroundColor', '#E8E8E8');
相关问题