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 />
我从这里看到了这些(Using the XHTML closing slash (/) on normal tags?)。
实际上我的主要问题是我们为什么使用这个?
我读到了答案: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):
正确吗?因为我们可以在这些字段中写入内部文本
<input />
<img />
<link />
所以我还是很困惑。请给我一个明确的答复。
最佳答案
HTML 中不存在自闭合标签之类的东西。
有些元素带有强制开始标签 ( <p>
)。有些元素带有强制结束标签 ( </script>
)。
有些元素带有可选的开始标签 ( <body>
)。有些元素带有可选的结束标签 ( </p>
)。
某些元素带有禁止的结束标签 ( <img>
)。 (没有元素具有禁止的开始标记)。
HTML 5 允许尾随 /
带有禁止的结束标签的元素的开始标签中的字符。这似乎是为了满足 XML 迷和糟糕的语法突出显示软件的需求。
您不能替换 /
以获得真正的结束标签。 HTML 解析器将倾向于忽略具有禁止的结束标记的元素的结束标记。 (但是,例如 IIRC,</br>
可能会产生奇怪的结果)
We can write inner text in these fields:
<input /><img /><link />
不能在 HTML 中(或 XHTML,它们被定义为不允许有子节点)。
关于javascript - html中的普通结束标签和自结束标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22452007/