浏览器会自动插入哪些DOM元素? [英] Which DOM elements do browsers automatically insert?

查看:53
本文介绍了浏览器会自动插入哪些DOM元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成供客户端使用的XPaths服务器端,我感到困惑的是为什么 only 表路径(即 td

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 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屋!

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