最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

timer - How to reset the time value of setTimeout() in Javascript? - Stack Overflow

programmeradmin5浏览0评论

I want to display an alert() box, just 10 seconds after user stops writting in a textbox.

I used following javascript code to open alertbox -

function txtkeyup(e){
  setTimeout(function () {
    alert('submit?');
  }, 10000);
  return true;
}

and the HTML code is -

<input type='textbox' name='searchquery' value='' onkeyup='return txtkeyup();'>

Now the browser is giving alertbox, 10 seconds after every onkeyup event in the inputbox. To make only one request, i have to reset the setTimeout() timer on every keyup event so the alertbox will be display if user doesnt press a button for 10 seconds.

How can reset the timer of previously called 'setTimeout()' in javascript? Please guide me..

I want to display an alert() box, just 10 seconds after user stops writting in a textbox.

I used following javascript code to open alertbox -

function txtkeyup(e){
  setTimeout(function () {
    alert('submit?');
  }, 10000);
  return true;
}

and the HTML code is -

<input type='textbox' name='searchquery' value='' onkeyup='return txtkeyup();'>

Now the browser is giving alertbox, 10 seconds after every onkeyup event in the inputbox. To make only one request, i have to reset the setTimeout() timer on every keyup event so the alertbox will be display if user doesnt press a button for 10 seconds.

How can reset the timer of previously called 'setTimeout()' in javascript? Please guide me..

Share Improve this question edited Nov 19, 2019 at 16:09 Mosè Raguzzini 15.9k1 gold badge32 silver badges44 bronze badges asked Aug 25, 2011 at 7:30 Vinay JeurkarVinay Jeurkar 3,1229 gold badges40 silver badges57 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 15

var myTimeout = setTimeout ( ...)

to clear it simply write clearTimeout(myTimeout);

发布评论

评论列表(0)

  1. 暂无评论