开发者

Help with jQuery show/hide on keyup

Basically I have a text box and when I type characters into the box it hides rows in my table that don't contain the text. How can I reform the following code so that it re-evaluates the function so that it starts showing the rows again when I press backspace?

This is as far as I got:

$("#txtFilter").k开发者_如何学Ceyup(function () {
                var text = $("#txtFilter").val();
                if () {
                    $(".tableStripe .tdName:not(:contains(" + text + "))").closest("tr").show();
                }
                else { 
                    $(".tableStripe .tdName:not(:contains(" + text + "))").closest("tr").hide();
                }
            });


You need to add the event var to your callback function, then specify the keycode for backspace:

$("#txtFilter").keyup(function(event) {
    var text = $("#txtFilter").val();
    if (event.keyCode == 8) { // 8 = keycode for backspace
        $(".tableStripe .tdName:not(:contains(" + text + "))").closest("tr").show();
    } else { 
        $(".tableStripe .tdName:not(:contains(" + text + "))").closest("tr").hide();
    }
});

For more javascript keycodes, do a google search for 'javascript keycodes'


try this one

var code = (e.keyCode ? e.keyCode : e.which);
 if(code == 8) { //Enter keycode
   //Do something
 }


Try this one:

$("#txtFilter").keyup(function () {
      $(".tableStripe tr").hide();
      setTimeout(function(){
            var text = $("#txtFilter").val();                                
            $(".tableStripe .tdName:not(:contains(" + text + "))").closest("tr").show();
      },10);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜