Home > Web Front-end > JS Tutorial > body text

A brief discussion on javascript syntax and timing functions

PHPz
Release: 2018-10-15 15:19:11
Original
989 people have browsed it

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)
{
}
Copy after login

2. DOM operation

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


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>
Copy after login

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template