jQuery get input value after keypress

后端 未结 9 1644
野趣味
野趣味 2020-11-28 21:40

I have the following function:

$(document).ready(function() {
    $(\"#dSuggest\").keypress(function() {
        var dInput = $(\'input:text[name=dSuggest]\'         


        
9条回答
  •  感动是毒
    2020-11-28 21:56

    Realizing that this is a rather old post, I'll provide an answer anyway as I was struggling with the same problem.

    You should use the "input" event instead, and register with the .on method. This is fast - without the lag of keyup and solves the missing latest keypress problem you describe.

    $('#dSuggest').on("input", function() {
        var dInput = this.value;
        console.log(dInput);
        $(".dDimension:contains('" + dInput + "')").css("display","block");
    });
    

    Demo here

提交回复
热议问题