简体   繁体   English

错误:具有 defer 属性的脚本元素不能具有带有 value 模块的 type 属性

[英]Error: A script element with a defer attribute must not have a type attribute with the value module

I have this code in the <head> -section:我在<head> -部分中有这段代码:

<script defer src="./static/js/main.js" type="module"></script>

The validator on validator.w3.org gives me the error: " A script element with a defer attribute must not have a type attribute with the value module. " validator.w3.org 上的验证器给了我错误:“具有 defer 属性的脚本元素不能具有带有 value 模块的 type 属性。

The javascript works fine and I am trying to understand the reason for the error. javascript 工作正常,我试图了解错误的原因。 What can I do to solve the error?我能做些什么来解决这个错误?

I found the answer on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script .我在https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script上找到了答案。

The defer attribute has no effect on module scripts — they defer by default. defer 属性对模块脚本没有影响——默认情况下它们会延迟。

The error message is a little bit confusing.错误消息有点令人困惑。 It suggests there is something wrong with the type-attribute.它表明类型属性有问题。 It would be a little bit more clear if it would say something like: " A script element with a type attribute with the the value module should not have a defer attribute. "如果它会说类似这样的话会更清楚一点:“一个带有 value 模块的 type 属性的脚本元素不应该有 defer 属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM