输入类型文本的任何侦听器

PPD*_*PPD 1 html jquery jquery-ui jquery-mobile

您好我的输入类型文本我想调用URL如果用户输入假设三个字符怎么做如何添加监听器?我正在开发搜索应用程序现在我在下面的代码中发送硬编码值"oil".这是我的代码:

<body>

<div data-role="page" id="mainPage">

    <div data-role="header">
        <h1>jQM Autocomplete</h1>

    </div>

    <div data-role="content">


        <p>
            <input type="text" id="searchField" placeholder="Categories">
            <ul id="suggestions" data-role="listview" data-inset="true"></ul>
        </p>

        <p>
            <a href="https://github.com/commadelimited/autoComplete.js" data-role="button">Download the code</a>
        </p>


    </div>

</div>

<script>

    $("#mainPage").bind("pageshow", function(e) {

        var substr,out,pra;

            var finalStr = "system"+encodeURIComponent("|^")+"0"+encodeURIComponent("|^")+"oil";
             var encodedURL = encodeURI("http://myDomainSearch.asp?requestString=");
             var parameters =  decodeURIComponent(finalStr);


        $.ajax({
        type: "POST",
        contentType:"application/x-www-form-urlencoded; charset=UTF-8",
        url: encodedURL,
        data: parameters
      }).done(function( msg )
              {
                  response  = msg
                    alert(response);
                    if(response.charAt(0)=='0')
                    {   
                        console.log("***"+ response);                                                         
                        substr = response.split('$');   

                        alert("inside if"+substr);

                        for (var out = 0;out<substr.length-1;out++)
                        {                       
                            pra = substr[out].split('|^');
                            console.log(">>>>>>>>>>>"+pra[0]);
                            console.log(">>>>>>>>>>>"+pra[1]);
                            console.log(">>>>>>>>>>>"+pra[2]);
                            console.log(">>>>>>>>>>>"+pra[3]);                  


                        }
                    }
                    else
                    {
                        alert("error")
                    }

                    $("#searchField").autocomplete({
                    target: $('#suggestions'),
                    source: pra,
                    link: 'target.html?term=',
                    minLength:1
                });
             }              
        );
    });
</script>
Run Code Online (Sandbox Code Playgroud)

现在我想要的不是硬编码值,如果用户在上面的输入类型文本中输入三个字符,那么它会点击URL并根据该响应将显示在列表中.

任何帮助将不胜感激.提前致谢.

the*_*dox 5

试着举个例子:

$('#searchField').keyup(function() {
  var val = $.trim( this.value );
  if(val.length == 3) {
    // do something
     .....
     ....
    var finalStr = "system"+encodeURIComponent("|^")+"0"+encodeURIComponent("|^")+ val;
  }
})
Run Code Online (Sandbox Code Playgroud)