html catch event when user is typing into a text input

前端 未结 4 1486
梦毁少年i
梦毁少年i 2020-12-31 01:53

Im just wondering how I go about catching the event when the user is typing into a text input field on my web application.

Scenario is, I have a contacts listing gri

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 02:42

    see my try:

    you should put .combo after every .input classes.

    .input is a textbox and .combo is a div

    $(".input").keyup(function(){
        var val = this.value;
        if (val.length > 1) {
            //you search method...
        }
        if (data) $(this).next(".combo").html(data).fadeIn(); else $(this).next(".combo").hide().html("");
    });
    
    $(".input").blur(function(){
        $(this).next(".combo").hide();
    });
    

提交回复
热议问题