<tag></tag> 有什么区别?和<标签/>在 HTML 中?

编程入门 行业动态 更新时间:2024-10-27 20:29:31
本文介绍了<tag></tag> 有什么区别?和<标签/>在 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>

更多推荐

&lt;tag&gt;&lt;/tag&gt; 有什么区别?和&lt;标签/&gt;在 HTML 中?

本文发布于:2023-11-04 10:31:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557688.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   标签   lt   amp   tag

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!