JavaScript statements

JavaScript statement sends a command to the browser. The purpose of a statement is to tell the browser what to do.

document.getElementById uses

Syntax: oElement = document .getElementById (sID)

Parameters: sID--required options. String.

Return value: oElemen--Object (Element).

Description: Get the object based on the specified id attribute value. Returns a reference to the first object whose id attribute value is equal to sID. If the corresponding object is a group of objects, the first object in the group is returned. If there is no matching object, return null .

Note: document.getElementById(" ") gets an object. Use alert to display "object" instead of a specific value. It has attributes such as value and length. Add .value to get is the specific value!

Details:

① document.getElementById sometimes captures name and lets go of id. It is said to be a BUG of IE

② GetElementbyId in javascript is used
in the web page The element must have an id attribute before it can be obtained through this method, such as

③There are two main ways to obtain html tags, one is Through the ID value, one is through the name attribute (the name attribute is mainly used for the input tag in the form.)

Note:

document.getElementById(" " ) What you get is an object. Use alert to display the

"object" instead of a specific value. It has attributes such as value and length. Add .value to get the

It’s a specific value!

    php中文网(php.cn) 

Semicolon ;

Semicolon is used to separate JavaScript statements.

Usually we add a semicolon at the end of each executable statement.

Another use of semicolons is to write multiple statements on one line.

a = 5;
b = 6;
c = a + b;

JavaScript Code

JavaScript 代码是 JavaScript 语句的序列。 浏览器按照编写顺序依次执行每条语句。 本例向网页输出一个标题和两个段落:     php中文网(php.cn) 

一句问候

一段话

JavaScript Code Blocks

JavaScript can be combined in batches.

A code block starts with a left curly brace and ends with a right curly brace.

The function of a code block is to execute a sequence of statements together.

This example outputs a title and two paragraphs to the web page:

    php中文网(php.cn)  

替代

覆盖

JavaScript statement identifier

JavaScript statements usually start with a statement The identifier starts with and executes the statement.

Statement identifiers are reserved keywords and cannot be used as variable names.

The following table lists JavaScript statement identifiers (keywords):

StatementDescription

##break is used to break out of the loop.

catch statement block, execute the catch statement block when an error occurs during the try statement block. .

continue Skip an iteration in the loop.

do... while Execute a statement block and continue executing the statement block when the conditional statement is true. for When the conditional statement is true, you can execute the code block a specified number of times.

for ... in is used to traverse the properties of the array or object (loop through the properties of the array or object).

#function Define a function

if ... else Used to perform different actions based on different conditions.

return Exit function

switch Used based on Different conditions perform different actions.

throw Throws (generates) an error.

try Implements error handling and is used with catch.

var declares a variable.

while When the conditional statement is true, execute the statement block

##

JavaScript is case sensitive.

JavaScript is case-sensitive.

When writing JavaScript statements, please pay attention to whether the case switching key is turned off.

The functions getElementById and getElementbyID are different.

Similarly, variables myVariable and MyVariable are also different.


Spaces

JavaScript will ignore extra spaces. You can add spaces to your script to make it more readable. The following two lines of code are equivalent:

var person="Hege";
var person = "Hege";


Wrap lines of code

You can wrap lines of code using backslashes in text strings. The following example will display correctly:

document.write("Hello\
world!");

However, you cannot wrap lines like this :

document.write \
("Hello world!");



##

Continuing Learning
||
php中文网(php.cn)
您的年龄:
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!