HTML:包含或排除可选的结束标记? [英] HTML: Include, or exclude, optional closing tags?

查看:106
本文介绍了HTML:包含或排除可选的结束标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些 HTML 1 结束标签是可选的,即:

 < / HTML> 
< / HEAD>
< / BODY>
< / P>
< / DT>
< / DD>
< / LI>
< / OPTION>
< / THEAD>
< / TH>
< / TBODY>
< / TR>
< / TD>
< / TFOOT>
< / COLGROUP>

注意:不要与禁止,即:

 < / IMG> 
< / INPUT>
< / BR>
< / HR>
< / FRAME>
< / AREA>
< / BASE>
< / BASEFONT>
< / COL>
< / ISINDEX>
< / LINK>
< / META>
< / PARAM>

注意 xhtml 与HTML不同。 xhtml是xml的一种形式,它要求每个元素都有一个结束标记。结束标记可以是禁止的HTML,但强制 xhtml 中。



是可选的结束标签




  • 包括 ,但我们会接受它们if您忘记了它们,或者 理想情况下不包含 ,但如果您将它们放入


换句话说,应该包含它们,还是应该不包含它们?



HTML 4.01规范讨论关闭元素标签是可选的,但并不表示是否最好包含它们,或者最好不要包含它们。

另一方面, DevGuru上的一篇随机文章说道:


结束标记是可选的。但是,建议将其包含在内。


我之所以问这个问题,是因为您只是知道,因为兼容性原因它是可选的;如果他们可以的话,他们会制作他们(强制 | 禁止)。

另一种说法是: HTML 1,2和3对这些(现在是可选的)关闭标签做了什么? HTML 5做什么?我应该怎么做?



注意



HTML中的一些元素是禁止结束标记。您可能会不同意这一点,但这是规范,并不适合辩论。我询问了可选的结束标签以及意图是什么。

脚注



1 HTML 4.01

解决方案

可选的都是应该在语义上清晰的地方他们结束了,不需要结束标签。
E.G.每个< li> 隐含一个< / li> >。


禁止使用的结束标签后面紧跟着结尾标签,因此必须输入< img src = blahalt =blah>< / img> 每一次。 我几乎总是使用可选的标签(除非我有一个非常好的理由不会),因为它提供了更易读和更新的代码。


Some HTML1 closing tags are optional, i.e.:

</HTML>
</HEAD>
</BODY>
</P>
</DT>
</DD>
</LI>
</OPTION>
</THEAD>
</TH>
</TBODY>
</TR>
</TD>
</TFOOT>
</COLGROUP>

Note: Not to be confused with closing tags that are forbidden to be included, i.e.:

</IMG>
</INPUT>
</BR>
</HR>
</FRAME>
</AREA>
</BASE>
</BASEFONT>
</COL>
</ISINDEX>
</LINK>
</META>
</PARAM>

Note: xhtml is different from HTML. xhtml is a form of xml, which requires every element have a closing tag. A closing tag can be forbidden in html, yet mandatory in xhtml.

Are the optional closing tags

  • ideally included, but we'll accept them if you forgot them, or
  • ideally not included, but we'll accept them if you put them in

In other words, should I include them, or should I not include them?

The HTML 4.01 spec talks about closing element tags being optional, but doesn't say if it's preferable to include them, or preferable to not include them.

On the other hand, a random article on DevGuru says:

The ending tag is optional. However, it is recommended that it be included.

The reason I ask is because you just know it's optional for compatibility reasons; and they would have made them (mandatory | forbidden) if they could have.

Put it another way: What did HTML 1, 2, 3 do with regards to these, now optional, closing tags. What does HTML 5 do? And what should I do?

Note

Some elements in HTML are forbidden from having closing tags. You may disagree with that, but that is the specification, and it's not up for debate. I'm asking about optional closing tags, and what the intention was.

Footnotes

1HTML 4.01

解决方案

The optional ones are all ones that should be semantically clear where they end, without needing the end tag. E.G. each <li> implies a </li> if there isn't one right before it.

The forbidden end tags all would be immediately followed by their end tag so it would be kind of redundant to have to type <img src="blah" alt="blah"></img> every time.

I almost always use the optional tags (unless I have a very good reason not to) because it lends to more readable and updateable code.

这篇关于HTML:包含或排除可选的结束标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆