Basic Javascript knowledge (I) Basic Core syntax and event model, basic javascript knowledge
I. Core basic Javascript syntax
1. Javascript is a programming language that increases interaction. It was originally invented by Netscape and finally submitted to ECMA (European Computer Manufacturers Association). ECMA standardizes Javascript and named it Javascript.
2. Javascript is an explanatory language that can be run directly in a browser without compilation.
3. What is the purpose of Javascript?
1. You can control all elements on the webpage, add, delete, and modify the attributes of the elements.
2. You can add dynamic text in html.
3. Respond to events generated when users use webpages.
4. Verify user input data.
5. Check your browser.
6. Create a cookie.
4. Three methods for creating Javascript in html Web pages
1. External style:
Create a file named xx. js through <script src = "xx. js"> <script>
2. Embedded style:
Use <script type = "text/javascript"> </script> or directly use <script> </script> to load a head or body in html.
3. inline style:
Add an event directly to the tag: <input onclick = "alert ('helloworld! ') "> Load
5. Javascript data type:
It has two types of data: 1. primitive data type 2. Reference Data Type (object)
Primitive data type: 1. typeof 2. number 3. string 4. boolean 5. null 6. undefined
Reference data type: (there are three types of predefined objects) 1. native Object (Object, number, string, boolean, function, Array, Date, etc.) 2. built-in object: No need to display initialization (math, Global) 3. host Object (mainly BOM and DOM)
6. BOM and DOM
BOM: Browser Object Model
DOM: Document Object Model
Ii. Javascript event model
1. javascript event model: 1. bubble type: <input type = "button"> when a user clicks the button: input-body-html-document-window (from bottom to top) the IE browser only uses bubble
2. Capture type: <input type = "button"> when you click the button: window-document-html-body-input (top-down)
After ECMA standardization, other browsers support two types. Capture occurs first.
2. Three traditional event writing methods:
1. <input type = "button" onclick = "alert ('helloworld! ') ">
2. <input type = "button onclick = name1 ()" >=====< script> function name1 () {alert ('helloword! ') ;}</Script> // famous Function
3. <input type = "button" id = "input1"> // anonymous Function
Copy codeThe Code is as follows:
<Script>
Var button1 = document. getElementById ("input1 ");
Button1.onclick = funtion (){
Alert ('helloword! ')
}
</Script>
3. Modern event writing methods:
Copy codeThe Code is as follows:
<Input type = "button" id = "input1"> // Add an event to IE
<Script>
Var fnclick (){
Alert ("I Have Been clicked ")
}
Var Oinput = document. getElementById ("input1 ");
Oinput. attachEvent ("onclick", fnclick );
--------------------------------------
Oinput. detachEvent ("onclick", fnclick); // delete an event in IE
</Script>
<Input type = "button" id = "input1"> // Add an event to the DOM
<Script>
Var fnclick (){
Alert ("I Have Been clicked ")
}
Var Oinput = document. getElementById ("input1 ");
Oinput. addEventListener ("onclick", fnclick, true );
--------------------------------------
Oinput. removeEventListener ("onclick", fnclick); // delete an event in the DOM
</Script>
<Input type = "button" id = "input1"> // compatible with IE and DOM add events
<Script>
Var fnclick1 = function () {alert ("I Have Been clicked ")}
Var fnclick2 = function () {alert ("I Have Been clicked ")}
Var Oinput = document. getElementById ("input1 ");
If (document. attachEvent ){
Oinput. attachEvent ("onclick", fnclick1)
Oinput. attachEvent ("onclick", fnclick2)
}
Else (document. addEventListener ){
Oinput. addEventListener ("click", fnclick1, true)
Oinput. addEventListener ("click", fnclick2, true)
}
</Script>
Basic javascript knowledge
You should understand JAVA well ~~
Objects can be hierarchical ~~~
Public class test {
Public string a = "";
}
Test t1 = new test ();
Test1.a = "B ";
It means something similar to the above ~~
Document is implemented by DOM ~~ What I said upstairs is wrong. javascript does not provide DOM and BOM objects. The implementation of these objects is provided by the browser ~~ In IE... you can use vbscript to implement document... Of course there are other languages to implement ..
All is a unique attribute of IE. It seems like it is. I'm not sure ~~ It means to return the collection of all the DOM in the document...
Form. numeric is the numeric object under the form object ~ This may be the case.
<Form id = "form"> <input type = "text" id = "numeric"/> </form>
The recommended book is <JavaScript advanced programming> ~ Is the Basic book ~~
If you do not want to buy books ~~ You can refer to the following two manuals... JScript manuals (JScript Language for MS, refer to 99%) and DHTML manuals (also for MS .. For DOM )~
Basic javascript Problems
Var bbb = aaa (); // return value when bbb is assigned aaa
====================
Var bbb = aaa;
// Bbb is assigned aaa by the address. Because aaa is a "function object", bbb is also a function object.
You can call bbb (). Here, the "function object" has nothing to do with the weak type. This is the language design that uses the function as the First-class function.
Javascript has no "reference" or "pointer" strictly ".
The concept of applying other languages is more metaphysical.
======================================
Xxx = getElementById ("idname"); // returns a DOM element object whose id is idname.
Xxx. onchange = func; // rewrite the onchange method of the element Object (I think of English override, which used the wrong Chinese translation ), the syntax here is to assign a value to the func function object.
Javascript emphasizes the concept of function objects. Because a function is the most basic object and a first-class citizen.
Function foo () {}// create a function
Equivalent
Var foo = new Function () {}// create a Function object
So
Xxx. onchange = foo
Xxx. onchange = new Function ("");
Xxx. onchange = function (){}
All point onchange to another function (object)
======================
To the pervasive francis674
Your answer is too wrong.
"Var a = funcitn (){}"
"A is a variable, the type is function, and alert (a) is the text definition of the function body"
Not only is spelling wrong, but it cannot be explained, so I had to say the content in the metaphysics.
I have never mentioned
Var a = function (){}
You can tell the subject that this is to define an unknown function in the form of function declaration.
Var a = new Function ("") is used to define Function objects.
These two types are interconnected.
"Xxx. onchange = func this is an event Delegate "// It is not an event Delegate. You only need to re-specify the object. When the object is not placed in the event model, you only need to re-specify the object in syntax and override the override object method.
"The essential difference is that it can be understood as a variable, a pointer, and actually a variable ."
Advanced languages have never been pointers, and blind analogy is metaphysics.
"Javascript is a weak scripting language. Both functions and variables are called variables. "// Can a function become a variable?
"Javascript does not support oop and other features" // does js not support oop or js? Js is the object-oriented programming language of the prototype model and supports oop very much.
These are all ridiculous and wrong. Why is it metaphysics? I learned some usage and hypothetical principles, mixed with many misunderstandings.
The method can only be obtained, but it can only be obtained. If you want to express all these mistakes to beginners? What can I learn from you? Shouldn't blame others for recognizing these mistakes .... Remaining full text>