Home  >  Article  >  Web Front-end  >  When getting focus, use js timer to set time to execute action_javascript skills

When getting focus, use js timer to set time to execute action_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:30:251528browse
Let’s get to the point, let’s talk about the timer first.
In javascript, there are two special functions for timers, namely:
1. Countdown timer: timename=setTimeout("function();",delaytime);
2. Loop timer: timename=setInterval("function();",delaytime);
The first parameter "function()" is the action to be performed when the timer is triggered. It can be a function or Several functions can be separated by ";". For example, if you want to pop up two warning windows, you can replace "function();" with
"alert('First warning window!'); alert('Second warning window!');"; and The second parameter "delaytime" is the interval time in milliseconds, that is, filling in "5000" means 5 seconds.
The countdown timer triggers an event after the specified time arrives, while the loop timer triggers the event repeatedly when the interval arrives. The difference between the two is that the former only works once, while the latter works continuously.
For example, after you open a page and want to automatically jump to another page every few seconds, you need to use the countdown timer "setTimeout("function();",delaytime)", and if you want to To set a sentence to appear one word at a time,
requires the use of the loop timer "setInterval("function();",delaytime)".

To obtain the focus of the form, document.activeElement.id is used. Use if to determine whether document.activeElement.id and the form's ID are the same.
For example: if ("mid" == document.activeElement.id) {alert();}, "mid" is the ID corresponding to the form.

Let’s give two examples.
Example 1. When the form is triggered or loaded, output the string
Copy the code The code is as follows:



Untitled Document


< ;body onload="setInterval('scroll()',second)">







Example 2. When the focus is on the input box, check the input box information regularly, and do not perform the check action when the focus is not on .
Copy code The code is as follows:

.org/1999/xhtml">


< title>Untitled Document













Example 3 .The following is the simplest example. A warning window pops up after the timer time is reached.

Copy code The code is as follows:






< div id="m">




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Extjs method to set automatic prompts in exlipse_extjsNext article:Extjs method to set automatic prompts in exlipse_extjs

Related articles

See more