2017-03-02 4 views

答えて

2

あなたはデバウンス機能が必要になります。どちらか使用lodash _.debounceまたはあなた自身の簡単なものを書く。そして、このようにそれを使用します。

jQuery("#width").on('input', debounce(function() { 
    alert('hello') 
}, 1500)) 

シンプルなデバウンス機能は次のようになります:

jQuery("#width").on('input', debounce(function() { 
 
    alert('hello'); 
 
}, 1500)); 
 

 
function debounce(callback, delay) { 
 
    var timeout 
 
    return function() { 
 
    var args = arguments 
 
    clearTimeout(timeout) 
 
    timeout = setTimeout(function() { 
 
     callback.apply(this, args) 
 
    }.bind(this), delay) 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<input type="text" id="width" />

+0

グレート男ありがとうA:ここで

function debounce(callback, delay) { var timeout return function() { var args = arguments clearTimeout(timeout) timeout = setTimeout(function() { callback.apply(this, args) }.bind(this), delay) } } 

はデモですロット。 :) – MageLerner

関連する問題