3. JavaScript Learning-IT software staff Learning series articles

Source: Internet
Author: User

Next, we begin to learn the JavaScript language.

The JavaScript language is an explanatory language, unlike the compiled language of the ASP. NET, C # language. It is published as an HTML page, meaning it is embedded in an HTML page to run.

Here's a simple JavaScript language:

<script type= "Text/javascript" >

Alert ("Hello World");

</script>

The above JavaScript script will display a dialog box and prompt for the "Hello World" string.

There are three ways in which JavaScript scripts are embedded in the page:

1, File link embedding method. Embed inside the head tag of the HTML page.

<script src= "Scripts/jquery/jquery-1.11.1.js" ></script>

The tag above tells the HTML page engine to find the JavaScript script language file and run it in the corresponding directory.

2, HTML page embedding method. Embed on the HTML page (inside the head and body of the HTML page).

<script type= "Text/javascript" >

var test = "";

var str = $. JSFn.PlugInInfo.Name;

$ ("#Label1"). html (str);

</script>

The JavaScript scripting language above sets the contents of the Label1 tag.

3. Embed directly in HTML tag attributes. Embed JavaScript scripts within HTML tags.

<input type= "button" id= "Btnok" onclick= "Javascript:alert (" Hello World ");"/>

The above script is embedded inside the button tag property, and clicking on the button will display the dialog box.

Ii. Overview of JavaScript language

The JavaScript language is case-sensitive, so the event onclick and onclick are not the same, this should be noted, when the script error is found, check the script casing problems. JavaScript consists of six data types: number, String, Boolean, Undefined, NULL, and function.

C. Programming of JavaScript language.

Referring to the concept of namespaces, these concepts of JavaScript are all under the window namespace.

Below is an example of a program:

Variable:

<script type= "Text/javascript" language= "JavaScript" >

var oopvar=new String ("JavaScript Variable OOP");

document.write (Oopvar);

document.write ("<br><br>");

Window.oopvar = "Window.oopvar";

document.write (Oopvar);

</script>

Function:

<script type= "Text/javascript" language= "JavaScript" >

function Oopfunction ()

{

return new String ("JavaScript Function OOP");

}

document.write (window. Oopfunction ());

</script>

Object:

<script type= "Text/javascript" language= "JavaScript" >

function Oopobject ()

{

This.title=new String ("JavaScript Object OOP");

}

var oopojbect=new oopobject ();

document.write (Window.oopOjbect.title);

</script>

The above code confirms that all of JavaScript's global variables, global functions, and global objects are based on the window namespace, or can be said to be based on the window's base class.

Here's another important concept in the JavaScript language: anonymous functions. Examples are as follows:

<script type= "Text/javascript" language= "JavaScript" >

function ()

{

This.title=new String ("JavaScript anonymity Function OOP");

}

</script>

Rather than an anonymous function, it is an important and special concept in the JavaScript language that a function without a function name is called an anonymous function.

I'll explain here again that the scope of the anonymous function is also based on the window namespace, except that, in syntax, we cannot invoke the anonymous function by invoking the function name. However, the anonymous function can be run as follows:

<script type= "Text/javascript" language= "JavaScript" >

(Function ()

{

Var title=new String ("JavaScript anonymity Function OOP");

document.write (title);

})();

</script>

Anonymous functions cannot be called by function names, but anonymous functions can be run indirectly through pointers, for example:

<script type= "Text/javascript" language= "JavaScript" >

var anonyobject=new function ()

{

This.title=new String ("JavaScript anonymity Function OOP");

This. Anonyfunction=function ()

{

return this.title;

}

};

document.write (Window.anonyObject.title);

document.write ("<br><br>");

document.write (Window.anonyObject.AnonyFunction ());

</script>

In the example, the first line, the Anonyobject object, points to an anonymous function. The object is based on the window namespace, so the contents of the anonymous function can be called through lines 10th and 14th. Note that the anonyobject here is an object that is not the same as the following function:

<script type= "Text/javascript" language= "JavaScript" >

function Anonyobjcet ()

{

This.title=new String ("JavaScript anonymity Function OOP");

This. Anonyfunction=function ()

{

return this.title;

}

};

var anonyobject=new anonyobjcet ();

</script>

In this example, you can assume that the Anonyobject object points to a function of the name Anonyobjcet.

The benefits of anonymous functions are many, and later.

Iv. JavaScript-related frameworks.

Now JavaScript has a lot of frameworks, such as ExtJS, jquery, Yui and so on, we will introduce the framework of jquery later.

Here are the books that JavaScript learns to read:

Http://pan.baidu.com/s/1ntMFOMH

3. JavaScript Learning-IT software staff Learning series articles

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.