Front-End Basic-javascript fourth day

Source: Internet
Author: User

Two small loops

Loop for ( initialize ; conditions ; Incremental ){}

While () when do {} and ()

while ( condition ) { statement }

Do while executing at least once while not necessarily

multi-branch Statement switch

Switch is almost the same as if else if else if else, but switch is more Efficient.

the role is actually : multiple selection 1 Choose 1 from a number of Inside.

Syntax format:

Switch ( parameter )

{

Case parameter 1:

statement ;

Break the meaning of the exit

Case parameter 2:

statement ;

Break the meaning of the exit

........

Default: defaults to

statement ;

}

drop -down Menu event onchange

sele.onchange = function () {}

when it's time to change Events

  Array Common methods Adding an array

The push () method adds one or more elements to the end of the array and returns the new Length.

Push push to go put

var arr =[1,3,5]→arr.push (7) → results become : [1,3,5,7];

The Unshift () method adds one or more elements to the beginning of the array and returns the new length

var arr = [1,3,5]→arr.unshift (0) → result becomes [0,1,3,5]

Attention

Delete array contents

Pop () Removes the last element

return value is a returns the last value

var arr = [1,3,5]→arr.pop () → results [1,3]

The shift () method is used to remove the first element of the array and return the value of the first element

var arr = [1,3,5]→arr.shift () → results [3,5]

Connect two arrays

Concat ()

This method is used to concatenate two or more arrays. It will not change the existing array, but will simply return a copy of the connected array

Join () converts an array to a string

Join ()

The function is to concatenate the elements of an array into a string by specifying the Delimiter.

Grammar

Arrayobject.join (separator)

array name . Join ( symbol )

Array conversion to string

converts a string to an array split ()

Join <=> Split

The split () method is used to split a string into a string array

Grammar

Stringobject.split (separator,howmany)

the parameter separator is optional. Specifies the delimiter to Use. If this argument is omitted, a comma is used as the Delimiter.

Howmany is Optional. This parameter can specify the maximum length of the returned array

DOM ( emphasis )

Document Object Model ( DOM) The focus of learning

methods and interfaces for handling Web page content

Browser Object Model ( BOM) Learn about

methods and interfaces for interacting with the browser

DOM Tree

Node

label    Mark    Elements node

Access node

getElementById () ID Access node

getElementsByTagName () Tag Access node

Getelementsbyclassname () class name has compatibility issues

Mainstream browser support IE 8 don't know

What to do? We encapsulate our own classes ourselves .

Encapsulate YourselfClassclassAccess relationship


node manipulation of the dom

new Node   inserting Nodes   Delete a node Clone node wait

Create a Node

the above means that generate a new Li tag

Inserting nodes

AppendChild (); Add Child Append Add the meaning

meaning:   Add Child put it on the last side of the box .

InsertBefore ( inserted node, reference node ) child node add child

Full two parameters

put it in front of the first child .

if a second parameter is null , the newly generated box defaults to the last Face.

removing nodes

RemoveChild () child node

Clone node

CloneNode ();

Replication Nodes

parentheses can be followed by parameters , if inside is true deep copy, In addition to copying this box, also copy child nodes

If a shallow copy is false, only copy this node does not copy the child Nodes.

Front-End Basic-javascript fourth day

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.