问题描述
在javascript中使用defer属性的正确语法是什么?
What is the correct syntax for using the defer attribute in your javascript?
我看过两种方式:
1:
<script defer >...</script>
2:
<script defer="defer">...</script>
根据经验[以及我找不到的参考]我更倾向于使用第二种选择,但是我只是仔细检查了,似乎选项1是正确的。
From experience [and a reference I cannot find] I am more inclined to used the second option, but I just double checked the official w3c site and it seems that option 1 is correct.
谢谢
推荐答案
defer
是:
[...]
在HTML中,布尔属性可能以最小化的形式出现 - 属性的值单独出现在元素的开始标记中。因此,选择
可以通过以下方式设置:
In HTML, boolean attributes may appear in minimized form -- the attribute's value appears alone in the element's start tag. Thus, selected
may be set by writing:
<OPTION selected>
而不是:
<OPTION selected="selected">
作者应该知道许多用户代理只识别布尔属性的最小化形式而不是完整形式。
Authors should be aware that many user agents only recognize the minimized form of boolean attributes and not the full form.
但是,如果你使用XHTML,你必须使用第二种形式,因为XHTML遵循XML语法,其中属性总是必须有价值。
However, if you use XHTML, you have to use the second form since XHTML follows XML syntax where attributes always have to have a value.
这篇关于推迟javascript - 什么是正确的html语法defer或defer =" defer"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!