Home  >  Article  >  Web Front-end  >  A brief discussion on javascript syntax and timing functions

A brief discussion on javascript syntax and timing functions

PHPz
PHPzOriginal
2016-05-16 16:01:34983browse

Beginners may misunderstand Javascript timers, thinking that they are threads. In fact, Javascript runs in a single thread, and timers are only scheduled to be executed at a certain time in the future, and the specific execution time cannot be Guaranteed, because during the life cycle of the page, other code may be controlling the Javascript process at different times.

1. Basic JavaScript syntax.

(1) Data types and variable types. Integer, decimal, layout, string, date and time, array coercion: parseInt() parseFloat() isNaN()

(2) Array var array name = new Array([length]); //" Fake "array a.length - length a[subscript] = value. a[subscript]

(3) Function

The code is as follows:

function 函数名(形参)
{
}
function ShowStr(a)
{
}

2. DOM operation

DOM - Document Object Model document object model. Tree
Linear model, tree model, mesh model
window
history
location
document

100db36a723c770d327fc0aef2ce13b173a6ac4ed44ffec12cee46588e518a5e
head
body
a, img, table, ul, ol....
status

Object - noun behavioral verb of object characteristics

(1) window 1.alert() window.alert();

2.[var a = ]window.confirm("Can you outrun a leopard? Why ask?"); //prompt(); - - It’s not commonly used, so don’t remember it. Enter

3.open(); open("Address", "_blank/_self", "Characteristics of 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 window type. Details require translation.

4.close(); window.close();

5.setTimeout("code", milliseconds) After the specified number of milliseconds, execute code once.

Example

<script language="javascript">
function showTime()
{
var date = new Date();
document.getElementById("hh").innerHTML = date;
window.setTimeout("showTime()",1000);
}
window.setTimeout("showTime()",1000);
</script>

Practice

Make a page where the home page will appear after 5 seconds

<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 is the entire content of this article, I hope you all like it.

【Related tutorial recommendations】

1. JavaScript video tutorial
2. JavaScript online manual
3. bootstrap tutorial

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