" and the syntax for external scripts is "" and the syntax for external scripts is "

Home  >  Article  >  Web Front-end  >  How to use js in html5?

How to use js in html5?

青灯夜游
青灯夜游Original
2019-04-28 10:45:416095browse

In HTML5, you can embed JavaScript code directly in the page and include external JavaScript files. The syntax for embedded scripts is "3f1c4e4b6b16bbbd69b2ee476dc4f83a2cacc6d41bbb37262a98f745aa00fbf0", and the syntax for external scripts It is "1d6bc41909296d18fd295bdfb5aeab612cacc6d41bbb37262a98f745aa00fbf0".

How to use js in html5?

In HTML5, js code can be used in two ways (embedded script and external script) through the 3f1c4e4b6b16bbbd69b2ee476dc4f83a tag. The following article will introduce it to you, I hope it will be helpful to you.

Two ways to use js in html5:

##There are two ways to use the 3f1c4e4b6b16bbbd69b2ee476dc4f83a tag: directly Embed JavaScript code in the page and include external JavaScript files; the browser will parse the 3f1c4e4b6b16bbbd69b2ee476dc4f83a elements in the order they appear on the page.

Embedded script:

External script:

Advantages of external script:

● Maintainability

● Cacheable: The browser can cache all external JavaScript files linked to based on specific settings

● Adaptable to the future

3f1c4e4b6b16bbbd69b2ee476dc4f83a tag

The main way to insert JavaScript into an HTML page is to use the 3f1c4e4b6b16bbbd69b2ee476dc4f83a element. The

3f1c4e4b6b16bbbd69b2ee476dc4f83a element has two commonly used attributes:

● src: Indicates the external file containing the code to be executed. The src attribute is required if you want to include external JavaScript files through the 3f1c4e4b6b16bbbd69b2ee476dc4f83a element. The value of this attribute is a link to an external JavaScript file.

Note: The 3f1c4e4b6b16bbbd69b2ee476dc4f83a element with the src attribute should not contain additional JavaScript code between its 3f1c4e4b6b16bbbd69b2ee476dc4f83a and 3f1c4e4b6b16bbbd69b2ee476dc4f83a tags. If embedded code is included, only the external script file will be downloaded and executed, and the embedded code will be ignored. JavaScript files from external domains can also be included via the src attribute of the 3f1c4e4b6b16bbbd69b2ee476dc4f83a element.

Example:


● Type: Specifies the MIME type of the script. The type attribute indicates the content between the 3f1c4e4b6b16bbbd69b2ee476dc4f83a and 2cacc6d41bbb37262a98f745aa00fbf0 tags.

Description: MIME type includes two parts: media type and subtype. For JavaScript, the MIME type is "text/javascript".

Note: In HTML5, the type attribute is no longer required. The default value is "text/javascript". JavaScript is the default scripting language in HTML5 and all modern browsers.

Recommended video tutorials: "

HTML5 Tutorial", "JavaScript Tutorial"

##

The above is the detailed content of How to use js in html5?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn