The best HTML <script> tag Tutorial In 2024, In this tutorial you can learn Examples,Browser Support,Tag definitions and instructions,Tips and Notes,Differences between HTML 4.01 and HTML5,Differences between HTML and XHTML,Attributes,Global Properties,related articles,
Through JavaScript output "Hello world":
All major browsers support the <script> tag.
<Script> tag is used to define client-side script, such as JavaScript.
<Script> element can contain script statements, you can also "src" attribute points to an external script file.
JavaScript is typically used for image manipulation, form validation, and dynamic content changes.
NOTE: If you use the "src" attribute, the <script> element must be empty.
Tip: See the <noscript> element, for those disabled in your browser script or a browser does not support client-side scripting users, this element is very useful.
Note: There are several ways to perform an external script:
In HTML 4 in, "type" attribute is required, but is optional in HTML5.
"Async" attribute is new in HTML5 attributes.
HTML5 no longer supported in HTML 4.01 in certain properties: "xml: space".
In XHTML, the script content type is declared as #PCDATA (instead of CDATA), it means that the entity will be resolved.
This means that in XHTML, all special characters should be encoded or all content nested in a CDATA section:
New: HTML5 new property.
属性 | 值 | 描述 |
---|---|---|
async New | async | 规定异步执行脚本(仅适用于外部脚本)。 |
charset | charset | 规定在脚本中使用的字符编码(仅适用于外部脚本)。 |
defer | defer | 规定当页面已完成解析后,执行脚本(仅适用于外部脚本)。 |
src | URL | 规定外部脚本的 URL。 |
type | MIME-type | 规定脚本的 MIME 类型。 |
xml:space | preserve | HTML5 不支持。规定是否保留代码中的空白。 |
<script> tag supports HTML global properties .
HTML Tutorial: HTML Script