Home >Web Front-end >JS Tutorial >JavaScript basic syntax, DOM operation tree and document object_Basic knowledge

JavaScript basic syntax, DOM operation tree and document object_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:29:391449browse

Part 1 Basic Grammar:

1. Data type (string, decimal, integer, Boolean, time and date)

Copy code The code is as follows:

var s="3.14" var n=parsefloat(s) s =5;
var s="abc3.14" var n=parsefloat(s) //NaN s =5;//Analyze and convert to decimal type
var d=parseInt(s)//Analyze and convert to integer type
isNaN (string), determine whether it is a string that looks like a number, yes - false; no - true

2. Variables
3. Operators: Four categories
4. Expression (to form a statement): variable operator
5. Statements: three major categories ()
Category:
Order
Branch: if;if..else,if..else..if..else...if..else;if nesting
switch...case
Loop: exhaustive method, iteration method; four elements (initial conditions; loop conditions; loop body; state change)
for...
while...
6. Array: var a= new Array();
7. Function: four elements (name, input, return, processing)

Copy code The code is as follows:

function show()
{
}

1. Operator

Comparison operators (7 types): ==/===/!=/>/=

=== (all equal to)

2. Usage of string substring

3. Practice question: Accumulation and summation (using Js method)

4. Base conversion

Part 2 DOM operation (operation html) tree

windows object--browser window
[window.document.
window.alert()]
window.location--address bar
window.history--forward, backward (access history)
window.status--status bar
window.document; (emphasis)

Part 3 document object :

1. Find

var d=document.getElementById("ID of element")
var d=document.getElementsByName("Name of element")
var d=document.getElementsByTagNme("Tag name of element")

2. Operation element content

Common elements: hyperlinks, pictures
Divided into 2 categories:
(1) Form elements (category 3) text (imput: type=text,password,textarea,hidden), button (submit/reset/button/image), selection (radio/checkbox/select drop-down list, list box/file)
Assign value d.value=xxxx;
Value var s=d.value
(2) Non-form elements: h1....h6;p;div;span;ul;ol;li (memory news)
Control format tag
Content container tag:
Assignment: d.innerHTML=xxxx;
Value: var s=d.innerHTML;

3. Manipulate element attributes

d.setAttribute(name, value)
var s=d.getAttribute(name)
d.removeAttribute(name)

4. Operation element style

(1) Inline style:
d.style xxxxx=xxxx;
var s=d.style.backgroundcolor;
(2)class attribute
d.className=""

5. Operation related elements
Up, down, inside, outside

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