jQuery get input value after keypress

后端 未结 9 1603
野趣味
野趣味 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:53

    You have to interrupt the execution thread to allow the input to update.

      $(document).ready(function(event) {
           $("#dSuggest").keypress(function() {
               //Interrupt the execution thread to allow input to update
                   setTimeout(function() {
                       var dInput = $('input:text[name=dSuggest]').val();
                       console.log(dInput);
                       $(".dDimension:contains('" + dInput + "')").css("display","block");
                   }, 0);
           });
      });
    

提交回复
热议问题