diff options
Diffstat (limited to 'files/zh-cn/web/api/document/body')
-rw-r--r-- | files/zh-cn/web/api/document/body/index.html | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/document/body/index.html b/files/zh-cn/web/api/document/body/index.html new file mode 100644 index 0000000000..e9ef372b55 --- /dev/null +++ b/files/zh-cn/web/api/document/body/index.html @@ -0,0 +1,29 @@ +--- +title: document.body +slug: Web/API/Document/body +translation_of: Web/API/Document/body +--- +<div> + {{ApiRef}}</div> +<h2 id="Summary" name="Summary">概述</h2> +<p>返回当前文档中的<code><body>元素</code>或者<code><frameset>元素</code>.</p> +<h2 id="Syntax" name="Syntax">语法</h2> +<pre class="syntaxbox"><em>var objRef</em> = document.body; +document.body = <em>objRef;</em></pre> +<h2 id="Example" name="Example">示例</h2> +<pre class="brush:js">// 如果HTML结构为<body id="oldBodyElement"></body>,则: +alert(document.body.id); // "oldBodyElement" + +var aNewBodyElement = document.createElement("body"); + +aNewBodyElement.id = "newBodyElement"; +document.body = aNewBodyElement; +alert(document.body.id); // "newBodyElement" +</pre> +<h2 id="Notes" name="Notes">介绍</h2> +<p><code>document.body</code>是包含当前页面内容的元素,对于拥有<code><body>元素的文档来说</code>,返回的是<code><body>元素</code>,对于一个拥有<code><frameset>元素的文档来说,返回的是最外层的</code><code><frameset>元素</code>.</p> +<p><code>该属性是可写的</code>,且为该属性赋的值必须是一个<code><body>元素.</code></p> +<h2 id="Specification" name="Specification">规范</h2> +<ul> + <li><a class="external" href="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-56360201">DOM Level 2 HTML: HTMLDocument.body</a></li> +</ul> |