gpt4 book ai didi

javascript - <script type=text/javaScript> vs <script type=module>

转载 作者:行者123 更新时间:2023-12-03 17:39:48 29 4
gpt4 key购买 nike

使用 <script type=text/javascript> 在 HTML 中加载 JavaScript 文件有什么区别?和 <script type=module> ?

最佳答案

HTML5 规范不鼓励使用 type=text/javascript :
来自 https://www.w3.org/TR/html5/semantics-scripting.html#element-attrdef-script-type :

Omitting the (type) attribute, or setting it to a JavaScript MIME type, means that the script is a classic script, to be interpreted according to the JavaScript Script top-level production. Classic scripts are affected by the charset, async, and defer attributes. Authors should omit the attribute, instead of redundantly giving a JavaScript MIME type.

Setting the attribute to an ASCII case-insensitive match for the string "module" means that the script is a module script, to be interpreted according to the JavaScript Module top-level production. Module scripts are not affected by the charset and defer attributes.


(我强调)

关于javascript - &lt;script type=text/javaScript> vs &lt;script type=module>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51418964/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com