Java Script Basics

Source: Internet
Author: User

Java Script Basics

JS must have a semicolon behind each statement.

<script type= "Text/java script" > All JS content </script>

Document. Write ("Hello"); the document does a write action, the action content is hello: The point is an operator, which means that the left side of the action or the right side is the left component, which indicates the action.

Alert ("Hello"), which represents the output of the page dialog box.

The abbreviation for VAR varible is used to define variables and can also be initialized at the same time. Example: var hello= "Hello"; var age=16;var ot=true; Defining variable names can have a numeric letter underline, but the first character cannot be a number, and the variable name cannot be the same as the keyword.

The + number represents the addition in the calculation, which represents both sides of the connection in the string.

In addition to the given case, the switch statement can be used by default.

The function function:function name (parameter) {Action statement} is used to define the function.

Arrays Array:var a=new Array (); Var a=[]; used to create an array.

Note: The [] operator accesses a cell in the array, starting with 0, A[x]=n directly creates a cell x in the vegetarian group and assigns a value of N.

Traverse the entire array: alert (a);

A.length gives the length of array A, where the maximum subscript is +1.

Convert array to String alert (a.tostring ()), Alert (a.valueof ()), Alert (A.join (",")), Alert (A.join ("| |)");

Array stack effect: Push, pop first drop out

Array queue operations: Shift-first-first-out

Object: is a composite data type, you can set multiple datasets in a variable and give each data a name. Var O=new object ();

Access Object properties: Var Book=new object (); Book.title= "Zhang San"

Delete Object properties: Delete Book.title; or book.title=null;

Traverse Object Properties: Get each of these properties for (Var x in book) {alert (book[x]) with a For loop;}

The browser's global object is: Window

Window.document represents an HTML page in a browser window

SRC is used to specify external files, a purely code file, no HTML tags

Body Event: OnLoad Onunlond

Simple dialog box: Output box alert (); Select box Confirm (); Input box prompt ();

Bottom status bar: status=, defaultstatus=

Timer: SetInterval () method invokes a function or evaluates an expression by a specified period (in milliseconds).

The SetInterval () method keeps calling functions until Clearinterval () is called or the window is closed.

The SetTimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds. SetTimeout () executes code only once. If you want to call more than once, use SetInterval () or let code itself call SetTimeout () again.

Window control method: window.open (); window.close;

Regular Expressions: Regeexp powerful string Matching tool. Looking for numbers in a string

var regexp=/\d+/g;alert (Str.match (REGEXP));//: Internal writing, \d: Find numbers, +: one or more; G: Global execution.

function Fun () {

var e=window.event| | Argument[0] (argument represents the event object, followed by 0 to get the current object directly)

}

Java Script Basics

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.