<分区>
谁能给我解释一下,为什么这段代码有效?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html<head>
<title//
<p ltr<span id=p></span</p>
</>
期待您的回复。感谢关注
标签 html validation
<分区>
谁能给我解释一下,为什么这段代码有效?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html<head>
<title//
<p ltr<span id=p></span</p>
</>
期待您的回复。感谢关注
最佳答案
那些 HTML 代码是有效的,因为 HTML 4.01 允许这些东西,并且尊重 doctype 的 Internet 浏览器将毫无问题地显示它。
如果将 doctype 更改为 HTML 5,肯定会报错,因为 HTML 5 对编写正确的 HTML 标记更加严格。
HTML 4.01(根据 https://validator.w3.org/#validate_by_input,没有错误):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html<head>
<title//
<p ltr<span id=p></span</p>
</>
HTML 5(15 个错误 根据 https://validator.w3.org/#validate_by_input ):
<!DOCTYPE html>
<html<head>
<title//
<p ltr<span id=p></span</p>
</>
解释:
该 HTML 结构是有效的,因为根据 HTML 4.0.1 规范 (https://www.w3.org/TR/1999/REC-html401-19991224/):
B.3.7 Shorthand markup
Some SGML SHORTTAG constructs save typing but add no expressive capability to the SGML application. Although these constructs technically introduce no ambiguity, they reduce the robustness of documents, especially when the language is enhanced to include new elements. Thus, while SHORTTAG constructs of SGML related to attributes are widely used and implemented, those related to elements are not. Documents that use them are conforming SGML documents, but are unlikely to work with many existing HTML tools.
The SHORTTAG constructs in question are the following:
- NET tags:
<name/.../
- closed Start Tag:
<name1<name2>
- Empty Start Tag:
<>
- Empty End Tag:
</>
引自https://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.3.7 .
因此,基于 HTML 4.01 规范,这意味着:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
2 <html<head>
3 <title//
4 <p ltr<span id=p></span</p>
5 </>
<html>
打开标签,关闭 </html>
标签不是必需的。<head>
打开标签,关闭 </head>
标签不是必需的。<title>
打开 Internet 浏览器读取的标签 <title// <p ltr<span id=p>
就像 <title>
, 关闭 </title>
标签不是必需的。<title>
的内容(内部HTML)标签是 </span</p> </>
(这是互联网浏览器显示为页面标题的内容)。这是我的补充说明。希望能帮到你。
关于html - 为什么这个 html 代码有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35600283/