[JavaScript] JavaScript learning 2 How to Implement Javascript

Source: Internet
Author: User
Tags comment tag html comment

The HTML <SCRIPT> label is used to insert Javascript into the HTML page.

Instance
Generate text
How to Write text in pages
Generate common text and tags
How to use JavaScript to write common text and labels to pages.
How to put Javascript into HTML pages
<script type="text/javascript">document.write("Hello World!");</script></body>

The above code will generate the following output in the HTML page:

Hello World! 
Example:

To insert Javascript into an HTML page, you need to use the <SCRIPT> tag (using the type attribute to define the script language at the same time ).

In this way, <SCRIPT type = "text/JavaScript"> and </SCRIPT> can tell the browser where JavaScript starts and ends.

<script type="text/javascript">...</script></body>

Document. WriteA field is a standard JavaScript command used to write output to a page.

After the document. Write command is input to the <SCRIPT type = "text/JavaScript"> and </SCRIPT>, the browser will execute it as a javascript command. In this way, the browser will write "Hello World!" to the page! ".

<script type="text/javascript">document.write("Hello World!");</script></body>

Tiy

Note: if we do not use the <SCRIPT> label, the browser will put document. Write ("Hello world! ") As plain text, that is, the command itself is written to the page.

Tiy

How to deal with old browsers

Browsers that do not support JavaScript will display scripts as page content. To prevent this, we can use the following HTML comment Tag:

<script type="text/javascript"><!--document.write("Hello World!");//--></script></body>

The two front slashes at the end of the comment line are the annotation symbols of JavaScript, which will prevent the Javascript compiler from compiling this line.

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.