浏览器会自动插入哪些DOM元素? [英] Which DOM elements do browsers automatically insert?
问题描述
我正在生成供客户端使用的XPaths服务器端,我感到困惑的是为什么 only 表路径(即 td $ c中的内容)
I am generating XPaths server-side for use on the client-side, and I was puzzled as why only table paths (i.e. content in a td
) couldn't be found in the DOM.
结果是,现代浏览器(至少是Chrome和Firefox)插入了 tbody
加载文档时在表行周围添加标记。请参见为什么浏览器将tbody元素插入表元素?
Turns out, modern browsers (at least Chrome and Firefox) insert a tbody
tag around table rows upon document loading. See Why do browsers insert tbody element into table elements?
除了 tbody
之外,在计算服务器端XPath时还有其他DOM元素吗?
Apart from tbody
, are there other DOM elements I should be aware of when calculating XPaths server-side?
推荐答案
在SGML / HTML4术语中,可以推断出其他一些元素,甚至是 head $ c可以推断出$ c>和
body
元素,HTML5继续这样做。因此,类似于 http://home.arcor.de/martin.honnen/html的文档/test2012011901.html 是有效的HTML5,尽管它既没有 head
也没有 body
元素和任何HTML5解析器应该添加它们,以便DOM树看起来像
In SGML/HTML4 terminology some other elements can be inferred, even the head
and the body
element can be inferred, and HTML5 continues that. So a document like http://home.arcor.de/martin.honnen/html/test2012011901.html is valid HTML5 although it does neither have head
nor body
element and any HTML5 parser is supposed to add them so the DOM tree looks like
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Test</h1>
<p>This is a test.</p>
</body>
</html>
我无法告诉您有关其他元素的所有详细信息,以上仅是示例。在 http://www.w3.org/TR/html5中查找详细信息/syntax.html#optional-tags 。
I can't tell you all details about other elements, the above is only an example. Look for details in http://www.w3.org/TR/html5/syntax.html#optional-tags.
这篇关于浏览器会自动插入哪些DOM元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!