Felayman-javascript Basics

Source: Internet
Author: User

Basic js content

<Script type = "text/javascript">

/*

Before learning javascript, we must make it clear that javascript can give me

What does it bring? What does it do as a scripting language?

The following issues are thrown out:

1. What is javascript?

1. javascript is designed to add interactions to html pages.

2. javascript is a scripting language parsed by browsers.

3. javascript is an explanatory language without compilation.

4. javascript scripts must be embedded into html code. Therefore, when the script introduced in a separate file involves a path issue, it must be a real path.

Either it is an absolute path and relative paths cannot be used in disorder, which is prone to errors.

2. What can javascript do?

1. javascript is a programming language specially designed for html designers.

2. javascript dynamically puts html code into the html page

3. javascript can dynamically respond to user operations

4. javascript can operate on html code

5. javascript can verify the content entered by the user

6. javascript can obtain information about your browser.

7. javascript can be used to create cookier

3. javascript Extension

The official name of JavaScript is "ECMAScript ". This standard is developed and maintained by ECMA

*/

// The following describes how to use javascript.

// 1. Generate Html code

Document. writeln ("I Am a hyperlink"); // The page itself does not have a tag

// 2. Generate text (common text, computer code)

Document. write ("plain text
Computer code");

// I usually follow the strict mode when learning, so I use the xhtml standard.

/*

3. for how to reference javascript, sometimes we hope that this script can be executed once a javascript script is introduced, such as loading some dynamic effects, however, sometimes we want the script to be triggered when the user operates the page.And are sent to the server as request headers. The latter is generally placed after the event triggered by user operations.

*/

// 4-digit CRC code block, which is similar to the code block in java and is composed of several javascript statements, as shown in

Document. write ("

");

Document. write ("hello ");

{

Document. write ("hello1 ");

Document. write ("world1 ");

Document. write ("felayman1 ");

}

// Alternatively, these two types can be encapsulated as code blocks for the js Code of the logarithm sentence.

{

With (document)

{

Write ("hello2 ");

Write ("world2 ");

Write ("felayman2 ");

}

}

Document. write ("

");

// Javscript comments are the same as java comments, but we still need to note that when we mix html, css, and javascript, we often cannot figure out their comments. errors may occur due to uniformity.

// I am a single line comment

/* I am a multiline comment */

// Javascript variables, we only need to remember that javascript variables do not differentiate data types during definition, but they still have data types, many developers always think that javascript is a weak type. In fact, I think it is still a strong type, because it is also divided into many data types, the operations on the data type are completed by the background operations of the browser, which gives developers an illusion.

// Javascript operators. I believe that any developer who enters the programming world with a c language can be familiar with operators, because the c operators are much more complex than javascript.

// Javascript flow statements. Most of these statements are familiar with c.

// Below we enter the most important section of javascript, ---- function

// Define the first function

Function fun (){

Document. write ("hello, function ");

}

// Call a function

Fun ();

// Define the second function

Var func = function (){

Document. write ("hello, function ");

};

Func ();

// Functions with Parameters

Function func1 (name ){

Document. write ("name =" + name );

};

Func1 ("felayman ");

// Functions with multiple parameters

Var func2 = function (name, age ){

Document. write ("name =" + name + ", age =" + age );

};

Func2 ("felayman", 22 );

// A function with a returned value

Function func3 (number1, number2 ){

Return number1 + number2;

}

Document. write (func3 (100,200 ));

// For Loop

Var sum = 0;

For (var I = 0; I <100; I ++ ){

Sum + = I;

}

Document. write (sum );

// Forin traversal of Arrays

Var arr = Array (1, 2, 3, 4, 5, 6, 7, 8 );

For (var key in arr ){

Document. write (key );

}

// Try-catch can only be said that javascript and php are gradually moving closer to java.

Try {

Var I = 0;

Var j = 0;

Docu (I + j); // exceptions are generally caused by the inability of the browser to parse statements.

} Catch (e ){

Alert ("an exception is thrown .");

}

</Script>

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.