submit form with delay while entering data into input field

后端 未结 2 560
無奈伤痛
無奈伤痛 2021-02-14 14:55

I have a simple form that I need to submit automatically when text is entered.

I can use the onChange or onKeyUp without the best result.

HTML is:



        
2条回答
  •  深忆病人
    2021-02-14 15:18

    This should work. Submits the form when nothing was typed for 500ms

    var timerid;
    jQuery("#fusionSearchForm").keyup(function() {
      var form = this;
      clearTimeout(timerid);
      timerid = setTimeout(function() { form.submit(); }, 500);
    });
    

提交回复
热议问题