1. JavaScript is a lightweight scripting language for browser parsing.
2, HTML, JSP and other internal JS code written in between <script></script>, external JS file to write JS code can not have <script></script>, because the reference to external JS, The JS code is referenced to the <script></script>,
Referenced by <script src= "./myscript.js" ></script> (referencing an external JS file, read from the WebContent folder by default, if an older item might read from Webroot)
3, JavaScript data display common way:
Window.alert ();//Browser hint box, window can omit
Console.log ();//write content to the console, often used for debugging, you can see the structure of the data
document.write ();//write content to the browser page
Innerhtml= "Add content between tags";
4, JS comments (single-line and multiline comments are the same as Java, JS and Java the same point is case-sensitive, ignoring the space, so it is indented; the variables start with a letter, not recommended by $ and _)
Single-line Comment
/* * * Multi-line Comment
5. Common Ways to select objects
document.getElementById ("myID");//element
Document.getelementsbyname ("name");//nodelist
document.getElementsByTagName ("Input");//nodelist
6. JS Type
8 Common data types: string number Boolean array object null (NULL, empty variable) undefined (the default value when the variable is assigned) function
Common 3 types of objects: Date Array Object
7, commonly used JS event
OnLoad//Browser page has finished loading
OnClick//Click events
Change//value changed, commonly used in drop-down list
onmouseover//mouse in an HTML tag
onmouseout//mouse to move out of an HTML tag
onkeydown//user presses the mouse button
8. Special characters in strings
such as: var str = "Double quotes inside double quotes" KDFJKDFJ "This is not correct"//all change to single quotation marks is not correct
Correct: var str = "Double quotation mark inside quotes \" Kdfjkdfj\ "This is not a good notation."
var str = "Double quotation mark ' KDFJKDFJ ' is not written"//internal use single quotation marks
9, fold the line with the backslash
Eg:document.write ("content before wrapping \
Post-line content ");//For a line of too long, wrapping, the backslash is resolved to a space
Ten typeof and Instanceof
var type = type of "AAA";//Displays the data type to which a variable belongs
var arr = [1, 2, 3, 4];
if (arr instanceof Array) {//Displays the object type to which an object variable belongs
document.write ("Arr belongs to array type");
}
10. Type Conversion
Other turn strings use ToString ();
String to value, Number (str),//parseint (str);p arsefloat (str);
Automatic type conversion:
document.write ("5" + null);//5null
document.write (5 + null);//5
document.write ("5" + 1);//51
document.write ("5"-1);//4
11, JS is expression
For example: var regExp = modifier of/e/i;//i regular expression, case-insensitive;/e/Regular expression body
Two methods:
Regexp.test (str);//true/flase;
Regexp.exec (str);//matches a lookup in STR, returns null if not found; returns the first
12. Form Verification
<form name= "Testform" action= "a.html" method= "POST" onsubmit= "return MyFunction ()" >
Testform<input type= "text" name= "name"/>
<input type= "Submit" value= "Submission"
</form>
Get forms: Document.forms[testform][name].value;
Add ID, get it with ID.
13. JSON
Json.parse (JSONSTR);//Convert JSON object to JS object
Json.stringify (jsobject);//Convert JS object to JSON object
14, javascript:void (0);//void (expression), the expression executes, the result is not received, so there is no response
The difference between href= "#" and href= "javascript:void (0)"
# contains a location information, the default anchor is #top is the top of the page.
and javascript:void (0), only represents a dead link.
When the page is long, it uses # to locate the page in the format: # + ID.
If you want to define a dead link please use Javascript:void (0).
15. Dom
<div id= "Div1" >
<p id= "P1" > This is a paragraph. </p>
<p id= "P2" > this is another paragraph. </p>
</div>
<script>
var para=document.createelement ("P");
var Node=document.createtextnode ("This is a new paragraph. ");
Para.appendchild (node);
var Element=document.getelementbyid ("Div1");
Element.appendchild (para);
</script>
Reference or reference in this article: Beginner's Tutorial
Http://www.runoob.com/js/js-tutorial.html
JavaScript must have basic knowledge