Javascript: Object-and event-driven scripting language, primarily for client
- Characteristics:
- Interactivity: Dynamic interaction of information.
- Security: Cannot access the local hard disk.
- Cross-platform: JavaScript is supported as long as there is a browser, regardless of the platform.
- How JavaScript and HTML are combined:
- <script type= "Text/javascript" >...</script>
- <script type= "Text/javascript" src= ".... js file"; Code is not executed </script>
- Variable:
var x = 4; (no obvious type) 3140/1000*1000=3140typeof (123) = number "X" +1= "121" typeof ("abc") = string "" -1= "1" typeof (3.45 ) = number " -1=nan" (illegal character)
- Operator and statement: while () {} if () {}else{} switch () {}
- Written in HTML: document.write (""); Line break: document.write ("<br/>");
- Functions: Function Show () {.... return ...;}. The function can be internally given a real parameter group, arguments[...], and with the length property. var sum = show, without brackets denotes sum function body
- Dynamic function: var func = new Function ("X, Y", "sum=x+y;return sum;");
- Anonymous functions: var func = function () {alert ("over");} is typically used for event invocation.
- Scope of variables: only variables defined within a function are local variables, others are global. for (Var i=0;i<5;i++) {...} The I in is also a global variable.
- Array: arr = [3,5,8]
- Characteristics:
- Containers for storing data
- The length is variable.
- The element type is arbitrary
- Strings can be directly compared
- var arr2=new Array (2); --Two arrays
- var arr2 = new Array (3,9)--two arrays with 3 and 9 contents
- You write a function, such as string comparison size, find the maximum value of the Getmax () function, you want to add to the tool class, you can:
Array.prototype.max = Getmax (); var Array = [3,5,8];
var ret = Array.max ();d ocument.write (ret);
You can also directly Array.prototype.max = function () {...; return;};
You can also use the. js file to import. js files in the. html you want to use, such as the trim () method.
String.prototype.trim = function () { var start = 0,end = This.length-1; while (Start <= end && This.charat (start) = = "") { start++; } while (Start <=end && this.charat (end) = = "") { end--; } Return this.substring (start,end);};
- JavaScript Object-oriented:
The function person (x, y) {///equals the definition class this.age = x; THIS.name = y; This.show = function () {...}; } var p = new Person (...,...); P.number = xxx; Arbitrarily join attribute members
The person class can also add new features, Person.prototype.toString = function () {...};
- JavaScript-specific statements:
P1.get (); --set (); Get ();}
-
- For (variable in object) {}--for traversing objects and arrays, such as for (X in P1) {alert (x+ ":" +p1[x]);} You can traverse the output properties and methods.
Java Foundation--javascript