表标签未嵌套在DOM中的P标签内 [英] Table Tag Not Nesting Inside P Tags In DOM
问题描述
我一直在动态地更改innerHTML内容,并注意到嵌套在其他元素内的表的某些奇怪行为.
I have been playin with dynamic changes to innerHTML content and have noticed some strange behaviour with tables nested inside other elements.
例如,表单p/p p表/table/p/form并未将表视为第二个p的innerHTML,而是将表列为该p标签的同级对象,而不是子级.
For example form p /p p table /table /p /form was not seeing the table as innerHTML of the second p but instead listed the table as a sibling of that p tag rather than a child.
我认为这是众所周知的行为.
I figure this is a well known behaviour.
我的知识渊博有何空白?
What is the gap in my knowlegde?
TIA
推荐答案
您不能将<table>
放在<p>
中.根据 HTML4规范:
You can't put a <table>
inside a <p>
. From the HTML4 specification:
<!ELEMENT P - O (%inline;)* -- paragraph -->
[...]
它不能包含块级元素(包括P本身).
<!ELEMENT P - O (%inline;)* -- paragraph -->
[...]
It cannot contain block-level elements (including P itself).
然后,如果您查看 %inline;
元素是什么, /a>,则在列表中找不到<table>
.
And then if you look at what the %inline;
elements are, you won't find <table>
in the list.
对于HTML5, <p>
可以包含措辞内容 :
And for HTML5, <p>
can contain phrasing content:
允许的内容
定语内容
a 或 em 或 strong 或小 ... 电表
a or em or strong or small ... meter
该列表中没有<table>
.
因此,您尝试插入无效的HTML,并且浏览器将<p><table></table></p>
更改为<p></p><table></table>
(即,将表子项向上移至同级项)以获取有效的HTML.
So you're trying to insert invalid HTML and the browser is changing <p><table></table></p>
into <p></p><table></table>
(i.e. moving the table child up to a sibling) in order to get valid HTML.
如果您给浏览器提供了无效的HTML,浏览器将猜测您的真实意思并附带其猜测.
If you give the browser invalid HTML, the browser will guess what you really mean and go with its guess.
这篇关于表标签未嵌套在DOM中的P标签内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!