2009-07-23 17 views

答えて

0

が、選択のあなた自身のJSライブラリを代用して自由に感じる:

var currentTimer = null; 
input.bind('keyup', function() { 
    if (!currentTimer) { 
     currentTimer = true; 
     setTimeout(function() { 
      if (currentTimer) { 
       currentTimer = null; 

       // Do ajax call here 
      } 
     }, 2000); 
    } 
}); 
0

私はここにjQueryを使用していますが、あなたはポイントを得る必要があります:あなたがしている場合は

function callAjax() { 
    timer = null; 

    // handle all your ajax here 
} 

var timer = null; 

$('input').keyup(function() { 
    // this will prevent you from reseting the timer if another key is pressed 
    if (timer === null) { 
     timer = setTimeout(callAjax, 2000); 
    } 
}); 
0

をjQueryを使用すると、優れたdelayedObserverプラグインを使用できます。

0

最後のキーを押すかキーを押すたびに2秒後?

<input type="text" id="txtBox" value="" width="200px"/> 
<input type="text" id="txt" width="200px"/> 

<script type="text/javascript"> 
    $(document).ready(function(){ 
    $("#txtBox").keyup(function(){ 
     setTimeout(function(){ 
      $("#txt").val($("#txtBox").val());//Here call ajax code 
     },2000); 
     }); 
    }); 
</script> 
+0

こんにちは、私はこのコードで行うことができます。私の場合、コードを実行すると、タイプされているものに関係なく2秒間待ってから実行します。他のキーが押された場合にタイマーを再設定できるようにmodできますか? – CaRDiaK