The basic code of JavaScript is simply understood, and it feels similar to the statements in C #.
1<! DOCTYPE html>234<!--use Var to declare variables, just declare variables, not specific types--5<title>javascript study</title>6<!--<script src= "commonjs.js" type= "Text/javascript" ></script>-->7<script type= "Text/javascript" >8 varF1 =function(I1, I2) {returnI1 + i2; }//the so-called anonymous function9Alert (F1 (3, 5));TenAlertfunction(x, Y) {returnx + y; } (2, 4));//Anonymous Life function One</script> A -<script type= "Text/javascript" > - functionPerson (name,age)//the declaration is not a class, similar to a class the { - This. name = name;//It has dynamically added properties. - This. Age =Age ; - This. SayHello =function() {Alert ( This. Name);}//Anonymous Functions + } - varp =NewPerson ("liming", 18); + P.sayhello (); A alert (p.age); at</script> -<script type= "Text/javascript" >//declaring a function; Notice the difference between the difference function and the above class-like - functionFun (I1, I2) {returnI1 +I2;} -Alert (Fun (10,12)); -</script> -<script type= "Text/javascript" >//where the array is used in varNames =NewArray (); -Names[0] = "Chenlong"; toNAMES[1] = "Wangxinyu"; +NAMES[2] = "Godness"; - for(vari = 0; i < names.length; i++) the alert (names[i]); *</script> $<script type= "Text/javascript" >Panax Notoginseng functionGetmax (arr) - { the varMax=arr[0]; + for(vari=1;i<arr.length;i++) A { the if(Max < arr[i]) max =Arr[i]; + } - returnMax; $ $ } - vararr =NewArray (); -Arr[0] = 1; theARR[1] = 5; -ARR[2] = 9;WuyiARR[3] = 4; theARR[4] = 12; -ARR[5] = 8; WuARR[6] = 7; - alert (Getmax (arr)); About</script> $<script type= "Text/javascript" > - //Practice reversing strings and connection strings - functionMyreverse (arr)//Here the parameter is a reference type and will affect the last original array after the change - { A for(vari=0;i<arr.length/2;i++) + { the vartemp =Arr[i]; -Arr[i] = arr[arr.length-i-1]; $Arr[arr.length-i-1] =temp; the } the returnarr; the } the functionMyjoint (arr) - { in varstr = arr[0]; the for(vari=1;i<arr.length;i++) the { Aboutstr + = "|" +Arr[i]; the } the returnstr; the } + varAR =NewArray (); -Ar[0] = "Long"; the BayiAR[1] = "Chen"; the myreverse (AR) the alert (AR); - alert (Myjoint (AR)); -Alert (ar[0]); the</script> the<script type= "Text/javascript" > the varDict =NewArray (); thedict["ren"] = "person"; -Dict["Man" = "men"; the alert (dict.ren); the for(varXinchDict//The object's key is displayed. the {94 alert (x); the } the varP1 =NewObject ();//properties can be dynamically added theP1. Name = "Tom";98P1. Age = 10; AboutP1. SayHello =function() {alert ("Hello"); } - for(varEinchp1)//the properties of a class can be taken out101 alert (e);102</script>103104<body> the<input type= "button" value= "click"/>106<a href= "Javascript:alert (' User hello ')" > Point me </a>107<a href= "www.baidu.com" onclick= "alert (' Enter Baidu website ')" > Baidu </a>108 109</body> theJavaScript code base