JavaScript Tags:
Two ways to introduce JS:
1.<script type= "Text/javascrip" >JS code </script>
2.<script src= "address/filename. js" type= "Text/javascrip" </script>
JS is either written between the head or written between the body.
Data type:
Variable declaration: var variable name = value;
var can omit variable name = value;
Type: NULL, Boolean, Integer, floating point (single, double), string, array, object, callback, NAN, Infinity (infinity), undefined (undefined)
JS Array (object)
New instantiation
var a = New Array ();
var b = [];
To read an element in an array:
b[Key Name]
Methods in the array
B.push ("Insert Value")
String (object)
var s = New String ();
var w = New String ();
y = "Chinese";
Properties and Methods
Length Leugth (attribute)
B.leugth
JS inside how to Output:
document.write ();
document.write (' ddd ');
Numeric index Array traversal
for (i=0;i<b.length;i++) {
Docuruent.write (B[i])
}
Console output
Console.log ();
Non-numeric indexed array traversal
For (i in B) {
B[i]
}
Declaration of the object
var object = {}; null value
Object = {Property: Property value, Property 2: Property value 2
Mtthod:function (parameter) {method one}
Mtthod:function (parameter) {method two}
};
Determine if a variable is defined
typeof tmp = = ""
var m = {
A: The value of the ' a attribute ',
B: The value of the ' B attribute '
Mtthod:function (A, b) {
if (a>b) {
return A;
}else{
return b;
}
},
Rand:function (A, b) {
Renturn This.max (A, b);
}
};
var B = M.rand (2.6);
Alert (' rand (2,6) = ' +b);
data type conversion;
1. Convert strings to integers: parseint () and Nuber ();
2. Convert strings to Floating point: parsefloat () and Nuber ();
3.eval () function: Executes a piece of JavaScript code represented by a string, such as: Zhang=eval ("+") results are zhang=2;
4. Numeric values are converted to strings: ToString () and string, e.g. b=567; C=b.tostring ();
Note: Use the typeof variable name to view the JS variable data type
5. Convert to Boolean: Boolean (); Boolean ("AAA") result is true;
6.JSON String Conversion:
JSON string: var str1= ' {' name ': ' cxh ', ' sex ': ' Man '} ';
JSON object: Var str2={"name": "Cxh", "Sex": "Man"};
To use the above str1 to convert the JSON string to a JSON object, you must first convert to a JSON object using the following method
var obj=eval (' (' +str+ ') ');
JavaScript basic information