Text Transform Color
1<script>2 varCC = [' Purple ', ' white ', ' black ', ' yellow ', ' gray ', ' blue ', ' green ', ' red '];3 vari = 0;4 functionMyc () {5 varu= document.getelementsbytagname (' H1 ') [0];6u.style.color=cc[i++];7 if(i>=cc.length-1){8I=0;9 }Ten}setinterval (myc,100); One</script>
The clock effect in the Web page two AA is the corresponding
1 function AA () {2 New Date (). tolocalestring (); 3 }
SetInterval (aa,1000);
Today is: April 16, 2015 10:44:36 Thursday
1 today is: <span id= "JNKC" class= "QQZCDTT" >
<script>document.write (new date (). toLocaleString () + ' Week ' + ' Day 123456 '. CharAt (new date (). GetDay ())) </script>
</span>
Time-sharing greetings
1 varD=NewDate ();2 varH=d.gethours ();3 if(H>8 && h<=12){4document.write (' Good Morning '));5}Else if(H>12 && h<=18){6document.write (' Good afternoon '));7}Else{8document.write (' Good evening '));9}
The square number squared can also be changed to PF or other English pf for the function name can be directly called Square pf (); I is the formal parameter function inside a see return immediately end
function Square (i) {
return; Program ends immediately return i*i;} Alert (Square ()); Calling functions
Two types of timers
1 /* 2s after output */ 2 setinterval (' Alert (200) ', 2000); /* every 2s output */
Confirmation Box:
1 Zhang San: <a href= "" onclick= "return confirm (' is not to delete Zhang San ')" > Delete </a>
Prompt Confirm Box One
1 if (Confirm (' whether to open Baidu Network ') {2 location.href= ' http://www.baidu.com '); 3 }
Prompt Confirm Box Two
1 var f=confirm (' whether to open Baidu Net ')2if(f) {3 location.href= ' http ://www.baidu.com '; 4 }
Input box
1 var i=prompt (' Please enter age ', "); 2 if (i<18) {3 alert (' minors are not allowed to surf the internet '); 4 }5 else{6 alert (' Adult allowed entry '); 7 location.href= ' http://www.baidu.com '; 8 }
Returns a random decimal between 0-1 math is an abstract object and cannot be instantiated that is not yy=new math ():
1 for (i=0;i<=10;i++) {2 document.write (math.random () + ' <br> '); 3 }
Math Mathematical Object
Alert (Math.Abs (-90));//90 Absolute Value
alert (MATH.PI);
Alert (Math.Round (4.1)); Rounded
Alert (Math.Round (4.5));
Alert (Math.Round (-4.1));
Alert (Math.Round (-4.5));
Alert (Math.floor (2)); Takes an integer that is less than the maximum integer of this number
Alert (Math.floor (2.9));
Alert (Math.ceil (2));//2
Alert (Math.ceil (2.3));//3 takes an integer greater than the smallest integer of this number
Alert (Math.ceil (2.9)); 3
Math.random (); Returns the random decimal between 1-0
Returns an integer between 0-3 to keep the background color changing
1 varc = Math.Round (Math.random ());//a random integer between 0-32 if(c==0){3Document.bgcolor = ' Red '; 4}Else if(c==1){5Document.bgcolor = ' Blue '; 6}Else if(c==2){7Document.bgcolor = ' green '; 8}Else{9Document.bgcolor = ' Purple '; Ten }
JS a few simple effects