JavaScript2 basis

Operators

Assignment operators to assign values ​​to variables. y = 5; / z = 2;

That arithmetic operators arithmetic symbols, the basic arithmetic operation. + Add / - subtraction / multiplication * / / addition /% fetch I / ++ increment (Y + assignment first and then the self-energizing / + Y increment and then the first assignment) / - decrement and increment empathy /

Compound operator + = x + = y plus other equivalent x = x + y The other principle / - + etc. Save / * = multiplication and other / / = the like in addition / modulo% = like

Base Event

Element by using the acquired ID: var leroy = document.getElementById ()

  Get var leroy = document.getElementByClass () by some other method for obtaining class of ...

Onclick event   click event

var leroy=document.getElementById();

leroy.onclick=function(){   alert();   }

onmouserover mouse moved events

leroy.onmouserover =function(){   alert();   }

onmouseout event mouse out events

leroy.onmouserout =function(){   alert();   }

Boolean type 

Or called Boolean Boolean data type is a base only two values ​​'true' or 'false'

The general relationship operator returns a Boolean value result, the value of special worth 0-0 null NaN undefined and null characters ( "") will be translated into other false value is interpreted as true 

Relational operators  perform a comparison operation

> Greater than / <less than /> = Greater than or equal to / <= less / equal == / === congruent /! = Ranged /! == full range

Uppercase character encoding all less than lowercase character encoding

Letter "a" can not be converted to a reasonable value, the turn is NaN. Any value to compare the relationship between NaN, the result is false.

<, <=,>,> = The same four budget precedence. /  

==,! =, ==,! == four operators have the same priority.

The first four operator has higher precedence than the four operands. Relational operators lower precedence than arithmetic operators. Relational operators higher priority than assignment operator

 Logical operator  for logical relationship between the measured variables or values

&& and / or || /! Non  

if statement   conditional statement to perform different actions for different conditions

Only when a specified condition is true, will execute code

 if (condition) {conditions must be true}

if (condition) {code is executed when the condition is true} condition is not performed when the else {true} code

if (condition) {XXXXX} else if (condition 2) {condition 2 is true when the execution code} else {xxxx}

The switch statement is used to perform different actions in different conditions

switch(n)

{     

      case1: executed 1

      break;

      case2: execute 2

      break;

      default: not simultaneously with case1 and case2;}

Ternary operator

var name=(condition)?value1:value2;

var n = 1 var car = (n == 1) 'Monday': 'Tuesday';?

onload event is generally used when writing code execution in the head after the page loads to keep the script content affected

 window.onload=function(){

         alert();

}

Therefore, we generally will script code in the bottom of the page, so that when running the script code, you can ensure that the objects to be manipulated has finished loading. To execute script code by window.onload.

for loop    code can be specified in the execution block Shu

for (single expression; conditional expression; the end of the loop) the loop body {intermediate;}

There LeRoy = o

for(var i=0;i<100;i++){  document.write(leroy.i+"<br>");}

JavaScript support different types of loops:

for - a certain number of cycles code block

for / in - loop through the properties object

while - when a specified condition is true cycle specified code block

do / while - when the code block of the same specified condition is true cycle specified

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/leroywang/p/12001888.html