<tag></tag> 有什么区别?和<标签/&a

What#39;s the difference between lt;taggt;lt;/taggt; and lt;tag /gt; in HTML?(lt;taggt;lt;/taggt; 有什么区别?和lt;标签/gt;在 HTML 中?)
本文介绍了<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 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Select OK button from N#39;th modal opened in testcafe(从 testcafe 中打开的第 N 个模式中选择 OK 按钮)
How to click a specified li for an autocomplete ul with Selenium IDE?(如何使用 Selenium IDE 为自动完成 ul 单击指定的 li?)
Test automation html element selectors. Element ID or DataAttribute(测试自动化 html 元素选择器.元素 ID 或 DataAttribute)
navigator.geolocation.getCurrentPosition not allowed on quot;file:///C:/quot; based access(“file:///C:/上不允许 navigator.geolocation.getCurrentPosition基于访问)
Geolocation not working on Safari 5.x on Windows 7/XP(地理定位在 Windows 7/XP 上的 Safari 5.x 上不起作用)
Request location coordinates after user has blocked access in javascript(用户在 javascript 中阻止访问后请求位置坐标)