2014-02-05 28 views
0

選擇有例如:http://jsfiddle.net/pVP6w/jQuery的動態表

$("#options1").change(function() { 
    $("#filter1").keyup(); 
}); 
$("#filter1").keyup(function() { 
    var filter1 = $("#filter1").val(); 
    var tr = $('tr').not(":nth-child(1)"); 
    if (!filter1.length) return tr.show(); 
    tr.hide().filter(function() { 
     var t = $('.wys', this).attr('data-wys'); 
     return operators[$("#options1").val()](t, parseInt(filter1)); 
    }).show(); 
}); 

如果你點擊按鈕,你看到了一些表格。 'td'設置屬性以優化下一步的搜索。

第一個輸入更改列值 第二個輸入更改列值2, 第三個輸入更改列值3, 最後並不重要。

如何連接所有表單以獲得一個共同的結果?現在,如果I鍵的任何形式的結果是從所有「TR」

回答

1

我優化你的代碼如你所說饒人,演示JSFIDDLE

$(document).ready(function() { 
    function eachcolom($that){ 
    $that.each(function() { 
      $(this).attr('data-wys',parseFloat($(this).text())); 
     }); 
    } 
    $("#inputs").hide(); 
    $("#detailed").click(function(){ 
     $("#inputs").toggle(); 

     eachcolom($('.wys')) 
     eachcolom($('.ctr')) 
     eachcolom($('.ok')) 



    }); 

    var operators = { 
     'equal': function(a, b) { return a == b }, 
     'notequal': function(a, b) { return a != b }, 
     'more':  function(a, b) { return a > b }, 
     'less':  function(a, b) { return a < b } 
    }; 
    function allForm($that, filt, ass, ty){ 
    var filter1 = $(filt).val(); 


     var tr = $('tr').not(":nth-child(1)"); 
     if (!filter1.length) return tr.show(); 
     switch(ty){ 
      case 'f': 

       filter1 = parseFloat(filter1); 
       break; 
      case 'i': 

       filter1 = parseInt(filter1); 
       //alert(filter1) 
       break; 

     }; 
     tr.hide().filter(function() { 
      var t = $("."+ass.attr('class'), this).attr('data-'+ass.attr('class')); 
      console.log(operators[$that.val()](t, filter1)) 

      return operators[$that.val()](t, filter1); 
     }).show(); 

    } 
    $("#options1").change(function() { 
     //allForm($(this),$('#filter1')) 
     $("#filter1").keyup(); 
    }); 
    $("#filter1").keyup(function() { 
     //alert('') 
     allForm($(this).prev('select'), this, $('.wys'), 'i') 
    }); 

    $("#options2").change(function() { 
     $("#filter2").keyup(); 
    }); 
    $("#filter2").keyup(function() { 
     allForm($(this).prev('select'), this, $('.ctr'), 'f') 

    }); 


    $("#options3").change(function() { 
     $("#filter3").keyup(); 
    }); 
    $("#filter3").keyup(function() { 
     allForm($(this).prev('select'), this, $('.ok'), 'f') 
    }); 
});