Javascript basics-Understanding javascript and javascript
Javascript basics-Understanding javascript
Every language begins with HelloWorld. I also follow this principle today! First, let's get to know about javascript.
<Html>
<Head>
<Title> javascript
</Title>
<Script language = "javascript" type = "text/javascript">
<! --
Alert ("Hello World Wide Web! ")
// -->
</Script>
</Head>
<Body>
</Body>
</Html>
This is a very simple program. When you open the page, the alert method will be called. A prompt box will pop up.
This method is simple, but it will take you a long time to learn javascript. This is a basic debugging method for javascript.
I. JavaScript features 1. It is a scripting language.
JavaScript is a scripting language that allows you to program using small program segments. Like other scripting languages, JavaScript is also an explanatory language that provides an easy development process. Its basic structure is similar to that of C, C, VB, and Delphi. But unlike these languages, it needs to be compiled first, but is interpreted row by row during the program running. It is combined with HTML tags to facilitate user operations.
2. JavaScript is based on objects and events (that is, it is dynamic)
It can directly respond to user or customer input without going through Web service programs. It responds to users in an event-driven manner. The event-driven action refers to the action produced by performing an operation on the home page. It is called an "Event ". For example, pressing the mouse, moving the window, and selecting a menu can be regarded as an event. When an event occurs, it may cause the corresponding event response.
One of the most powerful functions of javascript is to dynamically write data text, data, and even html tags to pages.
For example, you can add the last modification time.
<Script language = "javascript" type = "text/javascript">
<! --
Document. write ("The page was last modifild on" + document. lastModified)
// -->
</Script>
Function call
<Script language = "javascript" type = "text/javascript">
<! --
If (confirm ("Do you want to know the time? ")){
Display_time ()
}
Function display_time (){
Var now = new Date ()
Var hours = now. getHours ()
Var minutes = now. getMinutes ()
Var seconds = now. getSeconds ()
Var current_time = hours + ":" + minutes + ":" + seconds
Alert ("The current time where you are is" + current_time)
}
// -->
</Script>
In this example, a question is raised to the user using the confirm () method of javascript. The user answers the question by selecting OK or Cancel. If () statement checks its selection. If it is OK, the display_time () function is called.
3. Simplicity
The simplicity of JavaScript is mainly reflected in: first, it is a simple and compact design based on the Basic Java statements and control flow, so as to deal with learning Java is a very good transition. Second, its variable type is to accept weak types, and does not use strict data types.
4. Stability
JavaScript is a stable language. It does not promise to access a local hard disk, store data on the server, and does not promise to modify or delete network documents, information Browsing or dynamic interaction can only be achieved through a browser. This effectively prevents data loss.
5. Dynamic
JavaScript is dynamic. It can directly respond to user or customer input without going through Web applications. It responds to users by accepting event-driven methods. The Event-driven action refers to the action generated by certain operations on the Home Page. It is called an Event ). For example, pressing the mouse, moving the window, and selecting a menu can all be regarded as events. When an event is generated, it may cause the corresponding event response.
6. cross-platform
JavaScript depends on the browser itself and has nothing to do with the operating environment. As long as it can run the computer of the browser and support the JavaScript browser, it can be correctly executed. Thus realizing the dream of "writing once and going all over the world. In fact, the most outstanding thing about JavaScript is that it can do a lot of things with a very small program. There is no need for a high-performance computer, the software only needs a word processing software and a browser, without a WEB server channel, you can do everything through your own computer.
Javascript basic problem var bbb = aaa (); // the return value of 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? Other people should not be accused of such mistakes.
You should understand the basics of javascript well after learning JAVA ~~
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 )~