JavaScript learning the first day (how JavaScript is used)

Source: Internet
Author: User

The script in the HTML must be between the <script> and </script> tags. The script can be placed in the <body> and

1. Older instances may use the type= "Text/javascript" in the <script> tag. It is not necessary to do so now. JavaScript is the default scripting language in all modern browsers and HTML5.

2. Writing habits: The usual practice is to put functions into the

<!DOCTYPE HTML><HTML><Head><Script>functionmyFunction () {document.getElementById ("Demo"). InnerHTML="My First JavaScript Function";}</Script></Head><Body><H1>My Web Page</H1><PID= "Demo">A Paragraph.</P><Buttontype= "button"onclick= "myFunction ()">Click here</Button></Body></HTML>
3. External JavaScript

You can also save the script to an external file. External files typically contain code that is used by multiple Web pages.

The file name extension for external JavaScript files is. js.

To use an external file, set the. js file in the "src" attribute of the <script> tag:

<!DOCTYPE HTML><HTML><Body><H1>My Web Page</H1><PID= "Demo">A Paragraph.</P><Buttontype= "button"onclick= "myFunction ()">Click here</Button><P><b>Comments:</b>MyFunction is saved in an external file named "Myscript.js".</P><Scripttype= "Text/javascript"src= "/js/myscript.js"></Script></Body></HTML>

Tip: External scripts cannot contain <script> tags.

JavaScript Learning the first day (how to use JavaScript)

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.