JavaScricp, javascri

Source: Internet
Author: User
Tags array definition

JavaScricp, javascri

Common Dialog Box

1. alert (""): a warning dialog box is displayed.

2. confirm (""): In the confirmation dialog box, a dialog box with the OK and cancel buttons is displayed. -- confirm to return true, and cancel to return false.

3. primpt ("Text to be displayed"): a dialog box that allows users to enter content

 

Basic syntax

1. Variables

All are common var types. You can store other types of values and use them directly without defining them. But defined in habits.

Define variable: var a. All variable definitions are defined by var. var is a common variable type.

Var s = "3.14 ";

2. type conversion

It can be divided into automatic conversion and forced conversion. Generally, forced conversion is used.

Other types are converted to integers: parseint ();

Convert other types to decimal places: parsefloat ();

3. Operators

Mathematical operators: +-*/% + + --;

Relational OPERATOR: =! ==<=> <;

Logical OPERATOR: & | !;

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

4. Statements

It is generally divided into order, branch, and loop statements.

(1) Branch statement: if {} else {}

(2) loop for statement:

5. Array

Array definition: new Array (); // Its length changes dynamically, and any type of elements can be placed in it.

Array Element assignment: a [0] = 123; a [1] = "hello"; // The index in the element starts from 0.

Array value: a [I];

Array attribute: a. length; // the number and length of array elements. No count ()

Method: a. sort (); // sorts the array by the first character of each element.

A. reverse (); // flip the array.

6. Functions

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

Define function: function add (form parameter) {function body} // function name add. input is in the form of a parameter. The return value can be of the var type or return a return value.

Anonymous function: function () {function body}

The function can be executed only after it is called. Function call: add (real parameter)

 

Iii. Windows objects

(1) Part

1. window. open ("open address", "open Location ")

2. window. opener: Open the previous page object on this page.

3. window. close (): close the current page

4. window. navigate ("url") Jump to the target page (Hyperlink) with a bug in Google's browser (not commonly used)

5. window. moveTo (x, y) moves the page to a certain position, and the position is determined by x and y. (not commonly used)

6. window. resizeTo (width and height) Adjust the width and height of the page (not commonly used)

7. window. scrollTo (x, y) Where to scroll the page. y indicates vertical scrolling. (not commonly used)

(2) Window. history Object

Window. history. back (); the page is backward; -- mainly remember

Window. history. forward (); forward the page;

Window. history. go (n); if n is positive, it indicates that n pages are going forward. If n is negative, it indicates that n pages are backward.

(3) Window. location object

Location address bar

Window. location. href = "http://www.baidu.com"; modify the page address, jump to the page (Hyperlink) -- mainly remember

 

 

Forty-eight Windows Object --w.w.doc ument object

It can extract elements from Html to js and perform various operations on it.

It is the core of js.

(1) retrieving Elements

(1) docunment. getElementById ("id"); find one by id;

(2) docunment. getElementsByClassName ("name") based on classname, find the array;

(3) docunment. getElementsByName ("name"); find the array by name;

(4) docunment. getElementsByTagName ("name"); find the Tag name and find the array;

Note: It is best to use classname Based on the id.

 

(2) operation content

1. Common Elements

Value: alert (a. innerHTML) -- obtains all content in the element, including the element tag.

Alert (a. innerText) -- only take the text in it and ignore all compiled Elements

Value assignment: a. innerHTML = "<font color = red> hello world </font>" -- if the content has elements, compile and implement

A. innerText -- presents the assigned items as they are.

2. Change ticket Elements

Value: var t = document. f1.t1 -- input whose form ID is t1 in f1;

Var t = document. getElementById ("id") -- get it directly with ID.

Alert (t. value) -- obtain the value in input;

Value assignment: t. value = "content change ";

Note: value is used for values assigned to all form elements.

(2) operation attributes

1. Add and modify attributes

Object. setAttribute ("attribute name", "attribute value") -- if this attribute is not available, it is added. On the contrary, the value of this attribute is modified.

2. Get attributes:

Object. getAttribute ("attribute name") -- obtains the attribute value;

3. Delete attributes:

Object. removeAttribute ("attribute name") -- remove an attribute.

(3) Operation Style

1. Add and modify styles

Object. style. style name = Value
2. Get a style

Var... = object. style. style name

(4) related element operations-used to write general effects

Var a = document. getElementById ("id"); find;

1. var B = a. nextSibling -- find the Next Generation Element of a. Note that it contains spaces;

2. var B = a. previussibling -- find the last peer element of a. Note that it contains spaces;

3. var B = a. parentNode -- find the parent element of;

4. var B = a. childNodes -- find the array and find the next subelement of;

5. var B = a. firstChild -- the first child element, lastChild, and childNodes [n;

6. alert (nodes [I] instanceof Text); -- determines whether it is Text. true is returned, not flase. if is used to determine whether its value is false, spaces can be removed.

 

 

5. Events

1. onclick: Click to trigger

Ondblclick: Double-click trigger

2. onmouseover: triggered by moving the mouse above

Onmouseout: triggered when the mouse leaves

3. onblur: triggered when the focus is lost

Onfocus: Get focus is triggered

4. onkeyup: triggered when the button is lifted

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.