HTML and script.html
Labels are usually placed within the header label of an HTML web page, and are used to link external resource labels for external JavaScript files.Output "Hello world" with JavaScript:
document.write("Hello World!")
</script>
Try it out . . .
Browser support
All major browsers support the hashtag.
Label definition and instructions for use
The tag is used to define client scripts, such as JavaScript.
The element can contain both script statements and point to an external script file through the "src" property.
JavaScript is typically used for image operations, form validation, and dynamic content changes.
Tips and comments
Note: If the "src" property is used, the element must be empty.
Note: If the code inside the element is not in a function, the code is executed immediately when the page is loaded. The script after the label is ignored.
Tip: See the element, which is useful for users who disable scripts in their browsers or whose browsers do not support client scripts.
Note: There are several ways to execute an external script:
- If async is "async": The script executes asynchronously relative to the rest of the page (the script is executed as the page continues to parse)
- If you do not use async and defer is "defer": the script will execute when the page is resolved
- If you do not use async or defer: Read and execute the script immediately before the browser continues to parse the page
The difference between HTML 4.01 and HTML5
In HTML 4, the "type" property is required, but optional in HTML5.
The "async" property is a new property in HTML5.
Some properties in HTML 4.01 are no longer supported in HTML5: "xml:space".
The difference between HTML and XHTML
In XHTML, the content type in the script is declared #PCDATA (in place of CDATA), which means that the entity is parsed.
This means that in XHTML, all special characters should be encoded or nested in the CDATA section:
//<![CDATA[
var i=10;
if (i<5)
{
// some code
}
//]]>
</script>
Property
New : The new property in HTML5.
Attributes | value | describe |
---|---|---|
async New | async | Specify asynchronous execution scripts (only for external scripts). |
charset | charset | The character encoding is specified in the script (only for external scripts only). |
defer | defer | The rules are executed when the page has completed the parsing, and the script is executed (only for external scripts). |
src | URL | Specifies the URL of the external script. |
type | MIME-type | Specify the MIME type of the script. |
xml:space | preserve | HTML5 does not support. Specifies whether the gap in the code is retained. |
Global properties
Labels support the global properties of HTML.
Related articles
HTML tutorial: HTML script