推迟javascript - 什么是正确的html语法defer或defer =" defer" [英] Defering javascript - what is the correct html syntax defer or defer="defer"

查看:99
本文介绍了推迟javascript - 什么是正确的html语法defer或defer =" defer"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript中使用defer属性的正确语法是什么?

What is the correct syntax for using the defer attribute in your javascript?

我看过两种方式:

1:

<script defer  >...</script>

2:

<script defer="defer">...</script>

根据经验[以及我找不到的参考]我更倾向于使用第二种选择,但是我只是仔细检查了官方w3c网站,似乎选项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 4.01规范]


某些属性扮演布尔变量的角色(例如, OPTION 元素的选择属性)。它们出现在元素的开始标记中意味着属性的值为true。他们的缺席意味着价值假。

Some attributes play the role of boolean variables (e.g., the selected attribute for the OPTION element). Their appearance in the start tag of an element implies that the value of the attribute is "true". Their absence implies a value of "false".

[...]

在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 =&quot; defer&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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