Learn the summary of the first week of JavaScript

Source: Internet
Author: User
Tags logical operators tag name types of functions

A tribute to the Brandon Aick of JavaScript

Knowledge Points:

The 0.JS notation

If you encounter a-, remove the minus sign and capitalize the letter that follows the minus sign.

For example, CSS inside the margin-top, in JS inside to write: MarginTop.

HREF: "javascript:;"

A tag can use this empty JS statement when there is no content to write.

JS three-Step walk:

1.window.onload=function () {};

2.var getting elements

3. Add Event

1. Event (or attribute)

Window.onload Page Load Complete

OnClick

onmouseover

onmouseout

Onfocus Get Focus

Onblur loses focus

2. Get elements

document.getElementById ();

document.getElementsByTagName (); Get a set of elements from a tag name

Document.getelementsbyclassname ();

var Ali=oul.children Select all children

document.getElementsByTagName (") [0];

To get a set of elements, write the subscript (starting at 0) and specify the element with the subscript

An element with OBTN, a set of elements with ABTN

3. Process Control statements (that is, judgment)

The condition of the first if if is only true and false. You can judge which way to go by true or false. The standard for judging true and false is in 12th.

if (condition) {

Statement 1}

else{

Statement 2}

};

The first kind of enhanced version

if (condition 1) {

Statement 1}

else if (condition 2) {

Statement 2}

}else{

Statement 3

};

The second type: switch+case

Switch (variable) {

Case ' condition ';

Statement 1;

Break

Default

Statement

Break

}

4. Cycle

4.1 Cycle of Whil cycle uncertainties

(1) Initialize I=0

(2) Condition i<6

(3) Statement alert (i)

(4) Self-increment i=i++. The dead loop consumes performance if no increment is caught in the dead loop.

    

var i=0;

while (i<6) {

alert (i);

i++;

}

4.2 For loop has a fixed number of loops

for (var i=0; i<6; i++) {

Alert (1);

}

5.class is the only special thing in JS, to be written classname

6. String ' 12 ' +5=125

The quoted number is the string "" "

Two ways of writing an array

var arr=[1,2,3,4];

var Array (1,2,3,4);

InnerHTML

Changing the content of HTML elements

7. Data type

Detection data type: typeof

Basic type

String strings

Number numbers

Boolean Boolean value

Undefined not defined

Composite type

Object objects

function functions

Explicit data type conversions/coercion type conversions

Why would you turn

Some numbers, for example, may be identified as strings and converted into numbers for easy use.

parseint Integer

parsefloat integers, decimals/floating-point numbers

Number, strict numbers.

NaN non-numeric (just an identity)

Belong to the number type yourself not equal to yourself

Implicit type conversions

-minus * multiply/divide% mode. + Explicit type conversions are required, otherwise they will be identified as connectors.

8. Operators

+ - * / %

+= -= *= /= %=

Comparison operators

< > <= >=

!=   ==

===    !==

logical operators

! Non-inverting

&& and and

|| OR OR

9. Random number math.random (); 0-1 between 1 never appears

function rnd (n,m) {

Return parseint (Math.random () * (m-n) +n);

  }

10. Two types of functions

Named functions

Function Show () {definition

}

    Show (); Call

  Call mode: function Show (A, B) {Define a show function

Alert (A-B);

}

Show (12,5); Call this function and assign it to execute

  anonymous functions

Obj=function () {}; Call

function

One .return: Returns the value return 12; Show ();

Block the later programs

12. Criteria for judging true and false

  true- true

Non-0 numeric non-empty string non-empty object

  false- false

Number 0 empty string undefined (undefined) null (empty object) NaN

13. String manipulation

(1) str.indexof (' character ')

Check for the first occurrence of the character's subscript, if not found the return value-1

    Example: Var str= ' Dioauognosufoeiufosngvmlasisfji ';

Alert (Str.indexof (' a '));

  (2) Str.charat (digital)

Check for a character corresponding to a subscript, or null if the subscript exceeds the string length

    Example: Var str= ' Aojfsngosajfoijfoe ';

Alert (Str.charat (100)); 

(3) Str.lastindexof (' character ');

Returns the last occurrence of the corresponding subscript for the character

    Example: Var srt= ' KAFIAJFOIAIJEFONVOZJF ';

alert (str.lastindexof (' V '));

(4) str.substring (starting position, end position);

Cut a section that contains the start, not including the end. (If you write only one value, from the start position to the last)

    Example: Var srt= ' Diaufoueqqoijlljfoiv ';

var str2=str.substring (4);

alert (STR2);

(5)   str.touppercase ();   Turn Capital str.tolowercase (); Turn lowercase

    Example: Var str= ' abc ';

var str2=str.touppercase ();

alert (SRT2); 

(6)     str.split ("); go to array

    Example: Var str= ' ABCD ';

var arr=str.split (');

Alert (arr);

Screen Display A,b,c,d

14. Array manipulation

(1)

(2)

(3)

(4)

(5)

(6)

(7)

(8)

15. Time Objects

var odate=new Date (); Date Object

  var y=odate.getfullyear (); Years

var m=odate.getmonth ()+1; Month

  var d=odate.getdate (); Day

var day=odate.getday (); Week

var h=odate.gethours (); When

var m=odate.getminutes (); Score of

var s=odate.getseconds (); Seconds

var ms=odate.getmilliseconds (); Milliseconds

Practice:

1. Widen, get taller, change color, move left 300, return to normal, show/hide, change div
Shop NO. 2.1 Navigation top
3. One shop shopping cart (Click event)
4. After clicking on the search box, the text disappears.
5. Baidu Login (plus transparent layer)


Beauty says all the effects
AutoPlay tab
Countdown
Suning Countdown

Learn the summary of the first week of JavaScript

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.