HTML 属性需要引号吗? [英] Do HTML attributes need quotation marks?
问题描述
我正在开发一个网站,我想知道您是否需要在 HTML 属性周围加上引号,例如我看到过如下代码:
而不是:
<img src="http://example.com/image.jpg" width="350px" height="200px"/>
.
有人知道答案吗?
I am working on a web site, and am wondering if you need to put quotation marks around HTML attributes for example I've seen code like:
<img src=http://example.com/image.jpg width=350px height=200px />
instead of:
<img src="http://example.com/image.jpg" width="350px" height="200px" />
.
Does anyone know the answer to this?
推荐答案
如果属性包含非 ascii 或有空格的字符串,则需要将其用引号括起来
If the attribute contains a string that is not ascii or has whitespace then you need to wrap it in quotes
属性放置在开始标签内,由名称和一个值,以="字符分隔.属性值可以保留如果它不包含 ASCII 空格或任何 " ' ` = < 或>.否则,必须使用单引号或双引号引用它.该值以及="字符可以省略如果值是空字符串,则完全相同.
Attributes are placed inside the start tag, and consist of a name and a value, separated by an "=" character. The attribute value can remain unquoted if it doesn't contain ASCII whitespace or any of " ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted altogether if the value is the empty string.
链接这里
这篇关于HTML 属性需要引号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!