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

How to use js in html

coldplay.xixi
coldplay.xixiOriginal
2021-03-04 14:18:038761browse

How to use js in HTML: 1. Use [3f1c4e4b6b16bbbd69b2ee476dc4f83a] to embed JavaScript in HTML, and use the src attribute when using [3f1c4e4b6b16bbbd69b2ee476dc4f83a] to include external files; 2. All [27835793f4768f4164d1421d99e293bc] elements should be placed within the elements of the page.

How to use js in html

The operating environment of this tutorial: Windows 7 system, HTML version 4.01, DELL G3 computer.

How to use js in HTML:

1. The 3f1c4e4b6b16bbbd69b2ee476dc4f83a element

is used in HTML3f1c4e4b6b16bbbd69b2ee476dc4f83aEmbedded JavaScript

HTML 4.01 defines the following 6 attributes for

3f1c4e4b6b16bbbd69b2ee476dc4f83a.

  • async: Optional. Indicates that the script should be downloaded immediately, but should not prevent other operations on the page, such as downloading other resources or waiting for other scripts to be loaded. Only valid for external script files.

  • charset: Optional. The character set representing the code specified through the src attribute. This attribute is rarely used because most browsers ignore its value.

  • defer: Optional. Indicates that the script can be delayed until the document is fully parsed and displayed. Only valid for external script files. IE7 and earlier also support this attribute for embedded scripts.

  • language: Deprecated. Originally used to represent the scripting language used to write code (such as JavaScript, JavaScript1.2 or VBScript). Most browsers ignore this attribute, so there is no need to use it.

  • src: Optional. Represents an external file containing code to be executed.

  • type: Optional. Can be thought of as an alternative attribute to language; indicating the content type (also called a MIME type) of the scripting language used to write the code. Although both text/javascript and text/ecmascript have been deprecated, people have always used text/javascript. In fact, the

MIME type used by the server when transmitting JavaScript files is usually application/x–javascript, but setting this in type may cause the script to be ignored. In addition, the following values ​​can also be used in non-IE browsers:

application/javascript and application/ecmascript. Taking into account convention and maximum browser compatibility, the current value of the type attribute is still

text/javascript. However, this attribute is not required. If this attribute is not specified, its default value is still text/javascript.

There are two ways to use the 3f1c4e4b6b16bbbd69b2ee476dc4f83a element: embedding JavaScript code directly in the page and including an external JavaScript file. When using the 3f1c4e4b6b16bbbd69b2ee476dc4f83a element to embed JavaScript code, you only need to specify the type attribute for 3f1c4e4b6b16bbbd69b2ee476dc4f83a. Then, just place the JavaScript code directly inside the element like this:

The JavaScript code contained inside the 3f1c4e4b6b16bbbd69b2ee476dc4f83a element will be interpreted from top to bottom.

No other content on the page will be loaded or displayed by the browser until the interpreter has evaluated all

code inside the 3f1c4e4b6b16bbbd69b2ee476dc4f83a element.

When using 3f1c4e4b6b16bbbd69b2ee476dc4f83a to embed JavaScript code, remember not to include the 2cacc6d41bbb37262a98f745aa00fbf0 string anywhere in the code. If it must be present, use the / escape character 053a9cc4c2e9b9f6f911642332d34e85

Use the src attribute when including external files using 3f1c4e4b6b16bbbd69b2ee476dc4f83a. Processing of the page is stopped while external files are parsed (including downloads). No other code can be embedded in the middle of the 3f1c4e4b6b16bbbd69b2ee476dc4f83a with the src attribute, otherwise it will not be executed.

2. Tag position

According to traditional practice, all 3f1c4e4b6b16bbbd69b2ee476dc4f83a elements should be placed within the elements of the page, such as:

Do this or the browser will start displaying the page after all js files have been downloaded, parsed and executed (the browser will not start rendering content until it encounters the body)

In order to avoid this problem, modern Web applications It is common to place all JavaScript quotes after the page content in the element, as shown in the following example:




Example HTML Page

In this way, the content of the page will be fully rendered before the included JavaScript code is parsed in the browser. Users will also feel that the speed of opening the page is accelerated because the time the browser window displays a blank page is shortened.

3. Document mode

doctype

Mixed mode

Standard mode

Quasi-standard mode

4. 2b0b25ff593c5b6c03403dd6234ffb2c

This element can contain any HTML element that can appear in the document 6c04bd5ca3fcae76e30b72ad730ca86d - except the 3f1c4e4b6b16bbbd69b2ee476dc4f83a element. Content containing

in a

2b0b25ff593c5b6c03403dd6234ffb2c

element will only be displayed under the following circumstances: [ ] The browser does not support scripts;

[ ] The browser supports scripting, but scripting is disabled.

符合上述任何一个条件,浏览器都会显示2b0b25ff593c5b6c03403dd6234ffb2c中的内容。而在除此之外的其他情况下,浏览器不会呈现2b0b25ff593c5b6c03403dd6234ffb2c中的内容。示例:



Example HTML Page



相关学习推荐:html视频教程

The above is the detailed content of How to use js in html. 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