JavaScript (eight)--review One (important content is basically included)

Source: Internet
Author: User

first, The common dialog box

1. Alert (""): Warning dialog box, function is to pop up a warning dialog box

2. Confirm (""): OK Dialog box, pop up a dialog with OK and cancel Button--ok return true, Cancel return false

3. primpt ("text to display"): A dialog box that allows the user to enter content

Ii. Basic Grammar (similar to C #)

1. variables

are generic type var, can store other types of values, can be used directly, not defined. But it's customary to define.

Defining variables: var a; //all variable definitions are defined with var, var is a generic mutable type.

var s = "3.14";

2. Type conversion

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

Other types are converted to integers:parseint ();

Other types convert to Decimals:parsefloat ();

3. Operators

math operator : +-*/% + +-;

relational operators : = =! = >= <= > <;

logical operator :&& | | ! ;

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

4. statements

It is generally divided into sequential, branching, and cyclic statements.

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

(2) loop for statement :

5. Arrays

definition of the array: new array (); Its length is dynamically variable and can be placed in any type of Element.

Assignment of array elements: a[0]=123;  a[1]= "hello"; the index in the//element starts at 0.

The value of the array: a[i];

Array properties:a.length; the number of elements in the//array, Length. No Count ()

Methods: A.sort (); //array sorting, Sorted by the first character of each Element.

A.reverse (); //flip an Array.

6. Functions

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.

anonymous function: function () {body}

The function must be called to Execute. Call to function: add (argument)

third, Windows objects

(a) part

window.open ("open address", "open Position")

Window.opener: Open the previous Page object for this page

Window.close (): Close the current page

Window.navigate ("url") jump to the target page (hyperlink), in Google Chrome under the bug; (not used)

Window.moveto (x, Y) Moves the page to a location that is determined by X and y; (not commonly used)

Window.resizeto (wide, High) Adjusts the width and height of the page (not commonly Used)

Window.scrollto (x, Y) Scrolls the page to where Y represents portrait scrolling; (not used)

(ii) Window.history Object

window.history.back (); page Back;--main remember

Window.history.forward (); Page forward;

Window.history.go (n); n If a positive number represents the forward n pages, N is a negative number that represents back n pages, which is commonly used.

(iii) Window.location Object

Location Bar

window.location.href= "http://www.baidu.com"; Change page address, will jump page (hyperlink)--mainly remember

Iv. Windows Object--window.document Objects

It can extract elements from HTML into js, and then perform various operations on it.

It is the core of JS in the core

(i) Take the element

★docunment.getelementbyid ("id"); Search by id, up to one;

★docunment.getelementsbyclassname ("name") According to classname, find out the array;

★docunment.getelementsbyname ("name"); Search by name, find the array;

★docunment.getelementsbytagname ("name"); based on the name of the tag, find out the array;

Note: It is best to use the ID and classname

(ii) Operation Contents

1. Common Elements

value : Alert (a.innerhtml)-- All content within the element, including element tags, is taken out

Alert (a.innertext)-- takes only the text inside, ignoring all the compiled elements

Assignment : a.innerhtml = "<font color=red >hello World </font>"-- If content has elements, it is implemented after compilation

A.innertext--will present the things that are Assigned.

2. Change single element

value : var t = document.f1.t1--form Form ID is F1 with ID t1 input;

var t = document.getElementById ("id")--obtained directly with ID.

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

Assignment : t.value= "content change";

Note: all form element values are assigned with value

(ii) Operation Properties

1. Adding and modifying attributes

Object. setAttribute ("property name", "property value")--if No This property is added, the value of this property will be modified instead

2. Get properties:

Object. getattribute ("attribute Name")--gets The value of the property;

3. Delete Attributes:

Object. removeattribute ("property name")--removes a Property.

(c) Operation Style

1. Add and Modify Styles

Object. style. Style name = value
2. Get style

var ... = objects. Style. style name

(iv) operation of relevant elements--writing general purpose special effects

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

▲var B = a.nextsibling-- Find the next sibling element of a, Note that it contains spaces;

▲var B = A.previoussibling--find the previous sibling element of a, Note that it contains spaces;

▲var B = a.parentnode-- Find the Upper-level parent element of a;

▲var B = A.childnodes--is an array, looking for the next level of a sub-element;

▲var B = A.firstchild--first child element, lastchild last,childnodes[n] Find the number;

▲alert (nodes[i] instanceof Text);--judgment is not text, is return true, not return flase, use if to determine if its value is false, you can remove the Space.

V. Events

1. Onclick: Mouse click Trigger

Ondblclick: Double-click Trigger

2, Onmouseover: mouse movement above the trigger

Onmouseout: triggers when the mouse leaves

3, Onblur: Trigger when losing focus

Onfocus: get focus is trigger

4, onkeyup: Trigger when the button is lifted up

Complement: 1, Get the current height, width of an element ...--offsetheight, offsetwidth, offset what ...

2. Browser size Change event triggered: window.onresize

Note: some of the unused content can be seen in the previously published JavaScript essays

JavaScript (eight)--review One (important content is basically included)

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.