Javasrcipt using JavaScript in---HTML

Source: Internet
Author: User

Using JavaScript in HTML:

————————————————————————————————————————————————————————

Main content;

First, the use of <script> elements.

Second, embed script and external introduction script.

Third, the impact of document mode on Javasrcipt.

Four, under what circumstances consider disabling JavaScript.

————————————————————————————————————————————————————————

First, the use of <script> elements:

1, the main way to use JavaScript in a Web page is to use the <script> element to achieve. Now the <srcipt> element is a member of the HTML specification, with 6 attributes defined for the <script> element in HTML 4.01:

A, async-optional;

B, CharSet--optional;

C, defer--optional;

D, language--waste;

E, src--optional;

F, type--optional.

—————————————————————————————————————————————————————————

Ii. Embedding scripts and external introduction scripts

There are two ways to use it: the first is to write directly to the HTML page:

<script type= "Text/javascript" >

function Sayhi () {

alert ("Hello");

}

</script>

The code contained within the <script> element will be executed from the top to the next, and the interpreter will interpret a function of a function, and nothing else will change until a function has been interpreted.

The second method: embed the external JS file:

<script type= "Text/javascript" src= "Example.js" ></script>

This will enable the successful introduction of a JS file.

Note that if the JS code is written in the <script></script> element that contains the SRC attribute, the code here is ignored, or the JS file introduced by SRC is executed.

The <script> element is in that position in the HTML tag structure?

The <script> element is between

A few points of doubt:

Everyone knows that the HTML tag is executed from the top to the next line of execution, then the JavaScript tag side in the

The code loads a lot of time very long that would not be, load the time the browser will be blank, the inevitable user experience is poor this is a problem??

There are generally three ways to solve this problem:

1, put the <script> elements on the </body> elements above.

2. Use Lazy Load Properties "defer" Eg:<script type= "Text/javascript" defer= "defer" src= "Example.js" ></script>

3. Asynchronous loading defines the "async" attribute in HTML5.

The <noscript></noscript> tag element prompts the user to turn on the display script in a browser that does not support scripting or a script-disabled browser, and will never appear in a script-enabled browser.


Javasrcipt using JavaScript in---HTML

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.