blob: e9ef372b55ea263101207d3b79e57629b09cbd99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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>
|