📜  HTML script标签

📅  最后修改于: 2020-11-04 00:47:53             🧑  作者: Mango

HTML <script>  标签

HTML <script>  标签用于指定客户端脚本,例如JavaScript。它可以帮助您在HTML文档中放置脚本。

JavaScript用于图像处理,表单验证和动态内容。

<script>标签的语法如下:


HTML <script>标签的属性

Attribute Description Compatibility
src It specifies the URL of an external script file. HTML 4.01, HTML5
type It specifies the media type of the script. HTML 4.01
async It is a boolean value which specifies that the script is executed asynchronously. HTML5
defer It is a boolean value which is used to indicate that script is executed after document has been parsed. HTML 4.01, HTML5

<script>标签的用法

HTML <script>标签可以有两种用法:

  • 嵌入脚本代码
  • 链接脚本文件

<script>标签代码

<script>标签可以在要么标记以嵌入脚本代码。让我们看一下在HTML主体中具有script标签的示例。


输出:

JavaScript is a simple language for javatpoint learners

让我们看一下在HTML标头标签中包含<script>标签的示例。

 

链接脚本文件

script标签可用于通过src属性链接外部脚本文件。必须在仅标记。