简体   繁体   English

为什么 <content> 标签必须以开始标签和结束标签定义?

[英]Why the <content> tag must be defined with a starting and ending tag?

I used these two syntaxes in Firefox/Chrome to define a WebComponent. 我在Firefox / Chrome中使用了这两种语法来定义WebComponent。

Open tag 打开标签

<content></content>

Closed tag 封闭标签

<content/>

and both work as expected. 两者都按预期工作。

What are the (technical) reasons for defining <content> in the first way? 第一种定义<content>的(技术)原因是什么?


MDN Content element indicates that a starting and ending tag is mandatory , but doesn't specify why. MDN Content元素指示开始标记和结束标记是强制性的 ,但未指定原因。

You actually must use the <content></content> form. 实际上,您必须使用<content></content>表单。 In a normal HTML (non-XML) document (which is what you want to be making here), with the standard way that HTML parsing works in all browser engines, the <content/> tag is not a content end tag—instead it's just a content start tag with an extra / inside it that just gets ignored by HTML parsers. 在普通的HTML(非XML)文档中(这就是您要在此处进行的操作),使用HTML解析在所有浏览器引擎中均可使用的标准方式, <content/>标记不是 content结束标记,而是只是一个content开始标记,其中带有多余的/标记,HTML解析器会忽略它。

In your case, that means when an HTML parser doesn't see any </content> end tag for that content -start-tag-with-extra- / -at-the end, the parser never actually closes that content element , so that *all nodes that follow that content element become child content of it. 在你的情况,这意味着当一个HTML解析器没有看到任何</content>结束的标记, content -start标签与-预算外/特技的结束,解析器实际上从未关闭该content元素 ,所以*该content元素之后的所有节点都将成为其子内容。

To see what I mean, look at the DOM view of what the <content/> looks like to an HTML parser . 要了解我的意思,请查看<content/>对HTML解析器的外观的DOM视图

在此处输入图片说明

MDN Content element indicates that the empty tag form is mandatory, but doesn't specify why. MDN Content元素指示空标记形式是强制性的,但未指定原因。

I'm not sure what you mean by “empty tag form”. 我不确定“空标签表单”是什么意思。 That MDN page says: 该MDN页面显示:

Tag omission : None, both the starting and ending tag are mandatory. 标签省略 :无,开始和结束标签都是必需的。

That means the content element must have an end tag. 这意味着content元素必须具有结束标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM