What#39;s the difference between lt;taggt;lt;/taggt; and lt;tag /gt; in HTML?(lt;taggt;lt;/taggt; 有什么区别?和lt;标签/gt;在 HTML 中?)
问题描述
可能重复:
在普通标签上使用 XHTML 右斜杠 (/)?
自闭标签在 HTML5 中有效吗?
我正在审查大量 HTML 代码以及合成 HTML 的 JavaScript,我注意到如果标签内有一些没有内容的标签,那么有两种方法可以指定它.像这样:
I'm reviewing a lot of HTML code and also JavaScript that synthesizes HTML and I noted that if there's some tag without content inside the tag then there're two way to specify it. Either like this:
<div id="container"></div>
或者像这样:
<div id="container" />
这两者有区别吗?
推荐答案
浏览器将无效标记标准化为有效形式:
Browsers normalize invalid markup into the valid form:
<div/>
在技术上是无效标记 (HTML 5),因为 div
不是自闭合标签.
<div />
is technically invalid markup (HTML 5), as div
is not a self-closing tag.
浏览器会将其规范化为 <div>
.
A browser will normalize it to <div>
.
请注意,这与 XML 处理自闭合标签和闭合标签的方式不同.
Note that this is different from how XML will handle a self-closing tag compared to a closed tag.
自闭合标签没有子标签,也没有内部文本的值(null):
A self-closing tag has no children and no value for inner text (null):
<foo />
封闭标签没有子标签,也没有内部文本(空字符串):
A closed tag has no children and no inner text (empty string):
<foo></foo>
这篇关于<tag></tag> 有什么区别?和<标签/>在 HTML 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:<tag></tag> 有什么区别?和&a


- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01