2016-05-12 118 views

回答

4

绑定的事件处理程序,并检查文本长度的基础上,长度调用函数

$('.input-box').on('input', function() { 
 
    if (this.value.trim().length >= 4) { 
 
    // call your function here 
 
    doIt(); 
 
    } 
 
}); 
 

 
function doIt() { 
 
    alert('hi'); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<input type="text" class="input-box">

+0

谢谢,@pranav。得到我想要的。 –

+0

@ShafeequeS:很高兴帮助你 –

+0

@ShafeequeS如果这回答你的问题,请[接受答案](http://meta.stackoverflow.com/questions/5234/how-does-accepting-an-answer-work) – mplungjan