亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

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 <input type=textname="content" id="content">

③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!

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
    <p id="demo"></p>
    <script>
    document.getElementById("demo").innerHTML = "你好 summer";
    </script>
</body>
</html>

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 語句的序列。
瀏覽器按照編寫順序依次執(zhí)行每條語句。
本例向網(wǎng)頁輸出一個標(biāo)題和兩個段落:
<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
</head>
<body>
    <p id="demo">一句問候</p>
    <div id="myDIV">一段話</div>
    <script>
    document.getElementById("demo").innerHTML="你好 summer";
    document.getElementById("myDIV").innerHTML="你最近過得怎么樣?";
    </script>
</body>
</html>

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:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title> 
    <script>
    function myFunction(){
    document.getElementById("myPar").innerHTML="你好,世界!";
    document.getElementById("myDiv").innerHTML="這里要顯示一句話。";
    }
    </script>
</head>
<body>
    <p id="myPar">替代</p>
    <div id="myDiv">覆蓋</div>
    <p>
    <button type="button" onclick="myFunction()">點擊這里</button>
    </p>
</body>
</html>

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):

<table class="reference" "style="width: 100%" style="border: 0px; margin: 4px 0px; padding: 0px; width: 729px; color: rgb(51, 51, 51); font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, STHeiti, "Microsoft Yahei", sans -serif; font-size: 12px; line-height: normal; white-space: normal; widows: 1; background-color: rgb(255, 255, 255);">

Statement Description

##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
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script type="text/javascript"> function getAge(){ var age; age = document.getElementById("age_input").value; if ( age == "" ) { alert("請輸入您的年齡!"); return false; } if ( age > 25 ) { alert("您的歲數(shù)大于 25 歲。"); } else if ( age < 25 ) { alert("您的歲數(shù)小于 25 歲。"); } else { alert("您的歲數(shù)等于 25 歲。"); } } </script> </head> <body> 您的年齡:<input type="text" id="age_input" /> <input type="button" onclick="getAge()" value="確定" /> </body> </html>
submitReset Code