2016-05-12 119 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