JavaScript section of Web page 1-syntax (copy textbook content)

Source: Internet
Author: User

First, Introduction

1. JavaScript What is it, a thing?

It is a scripting language and requires a host file whose host file is an HTML file.

2 , it and Java What's the matter?

There is no direct connection, Java is Sun (No, has been acquired by Oracle), JavaScript is Netscape (Netscape has not, was bought by AOL), JScript is Microsoft, 90% like JavaScript, Some features can only be used on IE.

3 , the use of it

In the HTML position has three blocks: 1.head inside 2.body inside 3.

4 , three common dialog boxes

Alert ("") warning dialog box, function is to pop up a warning dialog;

Alert ("Error occurred"):

Confirm ("") determines the dialog box, the function is to pop up a selection of OK dialog box, after clicking OK, it returns ture, click Cancel to return flase, available variables to receive.

Confirm ("OK exit"):

Prompt ("Hint text to display"), which pops up a dialog box that allows you to enter content.

Prompt ("Lose a number come in", "can only be a number Oh"):

II. Statements and data types

1 , basic data type :

String, Decimal, Integer, DateTime, Boolean, and so on.

2. Variables:

are generic type var, can be stored casually other types of values, can be used directly, not defined, but customary definition. Define variables: var A; all variable definitions are defined with Var, var is a generic mutable type.

3. Type conversion:

It is divided into automatic conversion and casting, which is generally used for casting.

Other types converted to integers: parseint ();

Other types converted to decimals: parsefloat ();

In addition to determine whether it is a valid number type: IsNaN ();

is a number then returns false, not a number if it returns True, as follows:

var A;

Prompt ("Lose a number come in", "can only be a number Oh");

A=isnan ();

alert (a);

If you are entering a number:

The return value:

4. Operators:

Math Operator: +-*/% + +-;

Relational operators: = =! = > >= < <=;

Logical operator:&& | | !;

Other operators: + = = *=/=%=?:

5. Statement:

Generally divided into sequential, branching and looping statements.

(1) The branch is the IF statement:

If (Judging condition)

{

Statements that meet the criteria to be executed

}

Else

{

Statement to execute if the condition is not met

}

(2) Loop with for statement:

for (initial condition; cyclic condition; state change)

{

Loop body

}

(3) Problem type: exhaustive, iterative

(4) Two keywords: break and Continue

(5) If you want to output the value of a parameter: the value of the output is "+a+" and "+b

6. Array:

The definition of the array: the new Array (), whose length is dynamically variable, which can be placed in any type of element.

Assignment of array elements: a[0]=123;a[1]= "Hello";

Array value: A[i];

Array properties: a.length; Number of array elements, length.

Method: A.sort (); Sort an array, sort by the first character, A.reverse (); Flip an array

7. Function:

Four elements of a function: name, input, return value, processing.

Define functions: Function add (formal parameter) {function body}, function named Add, input as parameter, return value can be var type or return value;

Functions that do not call are not executed, called by the function: Add (argument).

JavaScript section of Web page 1-syntax (copy textbook content)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.