Keyup only after last key with jquery

后端 未结 3 1758
忘掉有多难
忘掉有多难 2021-02-05 06:14

I\'m coding a simple script to extract database informations on input keyup event.

The problem i have is that the keyup event is always repeated everytime the user press

3条回答
  •  眼角桃花
    2021-02-05 06:55

    var timer;
    
    $("input").on('keyup', function() {
        clearTimeout(timer);  //clear any running timeout on key up
        timer = setTimeout(function() { //then give it a second to see if the user is finished
            //do .post ajax request //then do the ajax call
        }, 1000);
    });
    

提交回复
热议问题