Beginners may misunderstand the JavaScript timer, think they are threads, in fact, JavaScript is running in a single thread, and the timer is only scheduled to be executed at some time in the future, and the specific execution time is not guaranteed, because in the page life cycle, There may be other code in the process of controlling javascript at different times.
First, JavaScript basic syntax.
(i) Data type and variable type. Integer, Decimal, Layout, string, date time, array cast: parseint () parsefloat () isNaN ()
(ii) array var array name = new Array ([length]); "Counterfeit" array a.length-length a[subscript] = value. a[Subscript]
(iii) function
Copy code code as follows:
function functions name (formal parameter)
{
}
function Showstr (a)
{
}
Second, Dom operation
Dom-document object Model Document objects. Tree
Linear model, tree-like model, mesh model
Window
History
Location
Document
Head
Body
A,img,table,ul,ol .....
Status
The verb of noun behavior--object characteristic of object
(i) window 1.alert () Window.alert ();
2.[var a =]window.confirm ("Can you run over the leopard?)" Prompt (); --not used, don't remember, enter
3.open (); Open ("Address", "_blank/_self", "features of the new Window"); [var a =]window.open ("http://jb51.net"); Open the page in a new window and return to the new window. A is also a variable of type window. Detailed translation is required.
4.close (); Window.close ();
5.setTimeout ("code", number of milliseconds) after the specified number of milliseconds, execute the code once.
Example
?
1 2 3 4 5 6 7 8 9 10 11 |
<script language= "JavaScript" > Function showTime () {var date = new Date (); document.getElementById ("hh"). innerhtm L = date; Window.settimeout ("ShowTime ()", 1000); } window.settimeout ("ShowTime ()", 1000); </script> |
Practice
Do a page in 5 seconds after the first page of the question
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14-15 16 |
<script language= "JavaScript" > var A; function Openad () {a = window.open ("http://hovertree.com", "_blank", "width=200" height=200 toolbar=no top=0 left=0); Window.settimeout ("Closead ()", 5000); function Closead () {a.close ();} window.settimeout ("Openad ()", 5000); </script> |
The above mentioned is the entire content of this article, I hope you can enjoy.