< script type = text/javaScript>与< script type = module> [英] <script type=text/javaScript> vs <script type=module>

查看:120
本文介绍了< script type = text/javaScript>与< script type = module>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the difference between loading JavaScript files in HTML using <script type=text/javascript> and <script type=module>?

推荐答案

HTML5规范不鼓励使用 type = text/javascript :

The HTML5 specification discourages the use of type=text/javascript:

来自 https://www.w3.org/TR/html5/semantics-scripting.html#element-attrdef-script-type :

省略(type)属性或将其设置为JavaScript MIME类型,意味着该脚本是经典脚本,将根据JavaScript Script顶级产品进行解释.经典脚本受字符集,异步和延迟属性的影响.作者应忽略该属性,而不是多余地提供JavaScript MIME类型.

将属性设置为字符串"module"的ASCII不区分大小写的匹配项.表示该脚本是模块脚本,将根据JavaScript Module顶级产品进行解释.模块脚本不受字符集和延迟属性的影响.

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.

(我强调)

这篇关于&lt; script type = text/javaScript&gt;与&lt; script type = module&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆