2014-02-14 52 views
1

我有一个jQuery脚本,用于在整行包含关键字时过滤表。不过,我想限制它只有一列,并有多个文本框,每列一个。我无法弄清楚这一点。有任何想法吗?在jQuery中按列过滤表

这里是脚本 http://jsfiddle.net/ukW2C/

$("#searchInput").keyup(function() { 
    console.log("value=%o", this.value); 
    //split the current value of searchInput 
    var data = this.value.split(" "); 
    //create a jquery object of the rows 
    var jo = $("#fbody").find("tr") 
    //hide all the rows 
    .hide(); 

    //Recusively filter the jquery object to get results. 
    jo.filter(function (i, v) { 
     var $t = $(this); 
     for (var d = 0; d < data.length; ++d) { 
      if ($t.is(":contains('" + data[d] + "')")) { 
       console.log(data[d]); 
       return true; 
      } 
     } 
     return false; 
    }) 
    //show the rows that match. 
    .show(); 
}).focus(function() { 
    this.value = ""; 
    $(this).css({ 
     "color": "black" 
    }); 
    $(this).unbind('focus'); 
}).css({ 
    "color": "#C0C0C0" 
}); 

回答

3

只看看在列要

http://jsfiddle.net/ukW2C/352/

var $t = $(this).children(":eq("+indexColumn+")"); 
+0

家伙我尝试了所有类型的组合,除了 “:EQ”。这工作谢谢你 – EGN