"Introduction of JavaScript Fang"

Source: Internet
Author: User

Javascript:

is Object-based and event-driven client script
Composition
Bom: Browse the Object model (methods and interfaces that interact with the browser)
Dom: Document Object Model (methods and interfaces for handling Web page content)
ECMA: Core (describes the syntax and basic objects of JS)

In summary, the commonly used several ways to introduce JS code:

1, the introduction of the page (head tag);

2, the introduction of the page (body tag inside);

3. Introduction of element Events (tag attribute introduced);

4, the introduction of external JS file;

First, the introduction of JS page header

The introduction of JS in the header refers to writing JavaScript within the

1 <!DOCTYPE HTML> 2 <HTML>3 <Head>4     <title></title>5     <Scripttype= "Text/javascript">6         //Write a JavaScript program here7     </Script>8 </Head>9 <Body>Ten </Body> One </HTML>

Description

<script type= "Text/javascript" >......</script> format is fixed, JavaScript code must be written within the <script></script> tag, And you must set the Type property value to "Text/javascript".

<script type= "Text/javascript" >......</script> this sentence to remember, oh, don't write a JavaScript program, even this sentence to come back here to copy the code past AH.

Second, the introduction of JS in the page

The introduction of JS in the page refers to writing JavaScript within the <body></body> tag.

1 <!DOCTYPE HTML> 2 <HTML>3 <Head>4     <title></title>5 </Head>6 <Body>7     <Scripttype= "Text/javascript">8         //Write a JavaScript program here9     </Script>Ten </Body> One </HTML>
Third, the introduction of JS in the element event

The introduction of JS in an element event means that a JavaScript program or call is written directly in a property of an element, which refers to the element's "event attribute".

1 <!DOCTYPE HTML> 2 <HTMLxmlns= "http://www.w3.org/1999/xhtml">3 <Head>4     <title></title>5 </Head>6 <Body>7     <inputtype= "button"OnClick= "alert (' Green leaf Learning net ')"value= "button"/>8 </Body>9 </HTML>

Iv. introduction of external JS files

The introduction of external JS files, the white is to put the JavaScript program in a suffix named. js file, and then use the script tag to refer to. In addition, the script tag that references the external JS file can be placed inside the head tag or in the body tag. Generally only with some plug-ins written in the head, most of it is written in the body of the bottom, because when the page loaded CSS and HTML is loaded first.

1 <  src= "js/index.js"  type= "Text/javascript"></  Script>

This is some of the commonly used JS introduction Way ~ ~ ~

"Introduction of JavaScript Fang"

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.