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

标签 javascript html

使用 <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/

相关文章:

javascript - 如何将生成的数字 ID 附加到某些链接

javascript - 一棵 DOM 树中的多个 Knockout 模型绑定(bind)

python - Django 没有将数据传递给 POST 请求的 View

php - HTML5 输入时间从 24 小时到 12 小时

javascript - 是否可以在JavaScript中捕获滚动条上的鼠标事件

javascript - 如何更改站点主体元素的背景以与幻灯片放映相对应?

javascript - 按字母顺序停止 AngularJS ng-repeat 渲染

javascript - 在此示例中,为什么在循环数组时需要数组名称?

javascript - 变量中的横向 DOM

html - 最大宽度 HTML 属性在 IE 和 Firefox 中不起作用,但在 Chrome 中有效