< tag>< / tag>的区别是什么?和< tag />在HTML中? [英] What's the difference between <tag></tag> and <tag /> in HTML?
问题描述
可能存在重复:
自我关闭标签在HTML5中有效吗?
我正在评论大量的HTML代码,以及综合了HTML的JavaScript,我注意到如果标签中没有内容,那么有两种方式可以指定它。或者像这样:
< div id =container>< / div>
或者像这样:
< div id =container/>
两者之间有什么区别?
< div />
div
不是自闭标记。 浏览器将它标准化为< div>
。
请注意,这与 XML 会处理一个自闭标签,与一个封闭的标签相比。
自闭标签没有子标签, ):
< foo />
一个封闭标签没有子元素,也没有内部文本(空字符串):
< foo>< / foo>
Possible Duplicate:
Using the XHTML closing slash (/) on normal tags?
Are self-closing tags valid in HTML5?
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>
or like this:
<div id="container" />
Is there any difference between the two?
Browsers normalize invalid markup into the valid form:
<div />
is technically invalid markup (HTML 5), as div
is not a self-closing tag.
A browser will normalize it to <div>
.
Note that this is different from how XML will handle a self-closing tag compared to a closed tag.
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>的区别是什么?和< tag />在HTML中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!