ajax call after x characters

前端 未结 3 616
感动是毒
感动是毒 2021-01-21 01:42

I have an ajax call triggering on the maxlength of an input. However, it continues to trigger if a user continues to enter characters (because they count as a keypress). Is ther

3条回答
  •  孤独总比滥情好
    2021-01-21 02:08

    Try this:

    var ready = true;
    $("input#billZipCode").on("keyup", function( event ){
        if(this.value.length == this.getAttribute('maxlength')) {
            if ($(this).valid() && ready) {
                zipLookup(this, "USA");
                ready = false;  
            }
        }
    });
    

提交回复
热议问题