如何在 HTML 中设置脚本异步执行?
htmlfront end technologyweb development更新于 2025/8/14 14:36:17
使用 async 属性将脚本设置为在可用时异步执行。它仅使用外部脚本。
首先,添加一个 js 文件。我们将其命名为 new.js
function sayHello() {
alert("Hello World")
}
现在让我们添加 HTML 代码并执行上述脚本 −
<html> <head> <script src = "new.js" ></script> </head> <body> <p>This is demo text.</p> </body> </html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

