Start 1 of JavaScript programming

Source: Internet
Author: User

Add javascript:

<Script language = "JavaScript"> // This line is a Javascript script tag, followed by a comment

Document. Write ("javascript displayed on the page") // display a sentence on the page
</SCRIPT>
/* This is also a comment,
But multiple rows.
*/

Numbers in javascript can be written in decimal, octal, and hexadecimal notation. The method is as follows:
Decimal: 15 (write a number directly)
Octal: 017 (use zero as the guiding number)
Hexadecimal: 0xf (using 0x as the guiding number)

Floating-point numbers are also called real numbers. For convenience, they can also be expressed using scientific Notation:
1.13e1, 1.5e3 (equivalent to 1.5 multiplied by 10 to the power of 3)
The number range of JavaScript is about 10 to the power of 308 to the power of 10.
There is also a special numeric value Nan (not a number) in Javascript. Javascript uses Nan to indicate this meaningless result. Boolean values: true and false. in computer systems, 1 indicates true, and 0 indicates false. Null is null, that is, nothing.
The undefined value is sometimes null, which may be a problem.
Special Character: Also called Escape Character. It is a special control character that cannot be displayed starting with a backslash.
/B: Return
/N: Indicates line feed.
And so on. Use of the alert () method:
<Script language = "JavaScript">
Alert ("display warning dialog box on the page ");
</SCRIPT>
Alert () is a javascript dialog box with a confirmation button. The information in the brackets is displayed.

Use of the confirm () method:
<Script language = "JavaScript">
Confirm ("display confirmation dialog box on the page ");
</SCRIPT>
Confirm () is similar to alert (). The difference is that a Cancel button is added. True is returned by pressing OK, and false is returned by pressing cancel.
<Script language = "JavaScript">
VaR con;
Con = confirm ("do you like this tutorial? ");
If (con = true) Alert ("like ");
Else alert ("dislike ");
</SCRIPT> Use of the prompt () method:
<Script language = "JavaScript">
VaR name, age;
Name = prompt ("your name? ");
Alert (name );
Age = prompt ("How old? ");
Alert (AGE );
</SCRIPT>
It not only displays information, but also can input information. Although most browsers support JavaScript, a small part of them are not supported. Or even if the browser supports JavaScript, the user closes the support for JavaScript for security and other reasons, what should be done:(1) <! -- Normally displayed in a browser that supports JavaScript and hidden in an unsupported Browser
Document. Write ("JavaScript code! ");
// Stop hiding --> (2) browsers that support JavaScript are certainly aware of the NoScript tag, so that the content in the middle of the tag will be ignored. Browsers that do not support JavaScript markup do not know NoScript markup, so that they can display the content and use this feature to handle browsers that do not support JavaScript.
<HTML>
<Head> the browser does not support JavaScript processing-NoScript <Body>
<Script language = "JavaScript">
<! --
Document. Write ("JavaScript code! ");
// Stop hiding -->
</SCRIPT>
<NoScript> your browser does not support JavaScript </NoScript>
</Body>
</Html>

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.