HTML中的普通结束标记和自结束标记 [英] Ordinary closing tag and self closing tag in html
问题描述
有人能说出html中普通结束标记和标记自标记之间的性能吗?
Can anyone tell about the Performance between ordinary closing tag and tag self tag in html?
<area />
<base />
<basefont />
<br />
<hr />
<input />
<img />
<link />
<meta />
我从这里看到了这些内容(使用XHTML斜杠(/)在普通标签上?).
I saw these from here(Using the XHTML closing slash (/) on normal tags?).
实际上我的主要问题是为什么我们要使用它?
Actually My Main question is why we use this ?
我从以下地址阅读了答案:有什么区别在< tag></tag>之间和< tag/>在HTML中?
I read the answer from :What's the difference between <tag></tag> and <tag /> in HTML?
答案是:
自动关闭标签没有子标签,内部文本也没有值(空):
A self-closing tag has no children and no value for inner text (null):
对吗?因为我们可以在这些字段中写内部文本
Is it correct? Because We can write inner text in these fields
<input />
<img />
<link />
所以我仍然感到困惑.请给我一个明确的答案.
So I am still confusing. Please give me a clear answer.
推荐答案
HTML中没有自动关闭标记之类的东西.
There is no such thing as a self-closing tag in HTML.
有些元素带有强制开始标记(<p>
).有些元素带有强制结束标记(</script>
).
There are elements with mandatory start tags (<p>
). There are elements with mandatory end tags (</script>
).
有些元素带有可选的开始标签(<body>
).有些元素带有可选的结束标签(</p>
).
There are elements with optional start tags (<body>
). There are elements with optional end tags (</p>
).
有些元素带有禁止的结束标签(<img>
). (没有元素具有禁止的开始标记).
There are elements with forbidden end tags (<img>
). (No element has a forbidden start tag).
HTML 5允许在开始标记中以结尾的/
字符结尾带有禁止结束标记的元素.这似乎是为了满足XML迷和糟糕的语法突出显示软件的目的.
HTML 5 allows a trailing /
character in start tags for elements with forbidden end tags. This appears to be for the purposes of satisfying XML junkies and poor syntax highlighting software.
您不能用/
代替实际的结束标签. HTML解析器将尝试忽略带有结束符的元素的结束符. (但是,例如IIRC,</br>
可能会产生奇怪的结果)
You cannot substitute a /
for a real end tag. HTML parsers will tend to ignore end tags for elements with forbidden end tags. (However, for example, IIRC, </br>
can produce odd results)
我们可以在以下字段中写内部文本:
<input /><img /><link />
您不能使用HTML(或XHTML,因为它们被定义为不允许的子节点).
You can't in HTML (or XHTML for that matter, they are defined as not being allowed child nodes).
这篇关于HTML中的普通结束标记和自结束标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!