Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1014643 of <body>

  • 版本网址缩略名: Web/HTML/Element/body
  • 版本标题: <body>
  • 版本 id: 1014643
  • 创建于:
  • 创建者: JoshuaLee
  • 是否是当前版本?
  • 评论
标签: 

修订内容

{{HTMLRef}}

摘要

HTML 主体元素 (<body>) 表示的是HTML文档的主体内容,任何一个HTML文档,只允许存在一个 <body> 元素。

  • 内容分类 Sectioning root.
  • 许可内容 Flow content.
  • 标记省略如果它的子元素不是空格、注释、{{HTMLElement("script")}} 元素或者 {{HTMLElement("style")}}元素的话,可以省略开始标签。如果body元素有内容或者有开始标签,或者不是以注释结尾就可以省略结束标签。
  • 父级元素body必须是{{HTMLElement("html")}} 的直接子元素 。
  • DOM 接口 {{domxref("HTMLBodyElement")}}
    • <body>元素暴露在{{domxref("HTMLBodyElement")}} 接口中。
    • 你可以通过 {{domxref("document.body")}} 属性来访问body元素。

属性

该元素包含所有全局特性

{{htmlattrdef("alink")}} {{obsolete_inline}}
超链接被选中时的颜色。这个方法不符合标准,请用元素的 CSS {{cssxref(":active")}} 伪类的{{cssxref("color")}} 属性代替。 
{{htmlattrdef("background")}} {{obsolete_inline}}
将用URI地址指定的图片设置为背景。这个方法不符合标准,请用元素的 CSS {{cssxref("background")}} 属性代替。
Note: Starting in Gecko 7.0 {{geckoRelease("7.0")}}, background is no longer resolved as a URI; instead, it's treated as a simple string.
{{htmlattrdef("bgcolor")}} {{obsolete_inline}}
文档的背景颜色。这个方法不符合标准,请用CSS {{cssxref("background-color")}} 属性代替。
{{htmlattrdef("bottommargin")}} {{obsolete_inline}}
body元素底部的空白。这个方法不符合标准,请用元素的 CSS {{cssxref("margin-bottom")}} 属性代替。
{{htmlattrdef("leftmargin")}} {{obsolete_inline}}
body元素左边的空白。这个方法不符合标准,请用元素的 CSS {{cssxref("margin-left")}} 属性代替。
{{htmlattrdef("link")}} {{obsolete_inline}}
未访问过的超链接的颜色。这个方法不符合标准,请用 CSS {{cssxref(":link")}} 伪类的 {{cssxref("color")}} 属性代替。
{{htmlattrdef("onafterprint")}} {{HTMLVersionInline(5)}}
用户打印完成当前文档后的回调函数。
{{htmlattrdef("onbeforeprint")}} {{HTMLVersionInline(5)}}
用户请求打印当前文档时(打印前)的回调函数。
{{htmlattrdef("onbeforeunload")}} {{HTMLVersionInline(5)}}
当文档即将被卸载的回调函数。
{{htmlattrdef("onblur")}} {{HTMLVersionInline(5)}}
DOM失去焦点的回调函数。
{{htmlattrdef("onerror")}} {{HTMLVersionInline(5)}}
DOM加载失败的回调函数。
{{htmlattrdef("onfocus")}} {{HTMLVersionInline(5)}}
DOM接收到焦点focus的回调函数。
{{htmlattrdef("onhashchange")}} {{HTMLVersionInline(5)}}
当文档当前地址的片段标识部分(地址后面以#号开始的部分)变化时的回调函数。
{{htmlattrdef("onlanguagechange")}} {{experimental_inline}}
语言改变时的回调函数。
{{htmlattrdef("onload")}} {{HTMLVersionInline(5)}}
DOM完成加载的回调函数。
{{htmlattrdef("onmessage")}} {{HTMLVersionInline(5)}}
DOM接收到message的回调函数。
{{htmlattrdef("onoffline")}} {{HTMLVersionInline(5)}}
网络连接失败的回调函数。
{{htmlattrdef("ononline")}} {{HTMLVersionInline(5)}}
网络恢复连接的回调函数。
{{htmlattrdef("onpopstate")}} {{HTMLVersionInline(5)}}
用户导航历史会话的回调函数。
{{htmlattrdef("onredo")}} {{HTMLVersionInline(5)}}
Function to call when the user has moved forward in undo transaction history.
{{htmlattrdef("onresize")}} {{HTMLVersionInline(5)}}
DOM大小调整时触发的回调函数。
{{htmlattrdef("onstorage")}} {{HTMLVersionInline(5)}}
存储区改变的回调函数。
{{htmlattrdef("onundo")}} {{HTMLVersionInline(5)}}
Function to call when the user has moved backward in undo transaction history.
{{htmlattrdef("onunload")}} {{HTMLVersionInline(5)}}
当文档已经被关闭的回调函数。
{{htmlattrdef("rightmargin")}} {{obsolete_inline}}
body元素右边的空白。这个方法不符合标准,请用元素的 CSS {{cssxref("margin-right")}} 属性代替。
{{htmlattrdef("text")}} {{obsolete_inline}}
文本的颜色。这个方法不符合标准,请用元素的 CSS {{cssxref("color")}}属性代替。
{{htmlattrdef("topmargin")}} {{obsolete_inline}}
body元素顶部的空白。这个方法不符合标准,请用元素的 CSS {{cssxref("margin-top")}} 属性代替。
{{htmlattrdef("vlink")}} {{obsolete_inline}}
已访问的超链接的颜色。这个方法不符合标准,请用 CSS {{cssxref(":visited")}} 伪类的 {{cssxref("color")}} 属性代替。

规范

Specification Status Comment
{{SpecName('HTML WHATWG', 'sections.html#the-body-element', '<body>')}} {{Spec2('HTML WHATWG')}} Changed the list of non-conforming features.
{{SpecName('HTML5 W3C', 'sections.html#the-body-element', '<body>')}} {{Spec2('HTML5 W3C')}} Obsoleted the formerly deprecated attributes. Defined the behavior of the non-conforming and never standardized margintop, marginleft, marginright and marginbottom.
{{SpecName('HTML4.01', 'struct/global.html#h-7.5.1', '<body>')}} {{Spec2('HTML4.01')}} Deprecated the alink, background, bgcolor, link, text and vlink attributes.

浏览器兼容性

{{CompatibilityTable}}

特性 Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
支持 1.0 {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
onlanguagechange {{CompatUnknown}} {{CompatGeckoDesktop("32")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
bottommargin, leftmargin, rightmargin, topmargin {{obsolete_inline}} {{CompatVersionUnknown}} {{CompatGeckoDesktop("35")}} [1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
特性 Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
支持 {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
onlanguagechange {{CompatUnknown}} {{CompatGeckoMobile("32")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
bottommargin, leftmargin, rightmargin, topmargin {{obsolete_inline}} {{CompatVersionUnknown}} {{CompatGeckoMobile("35")}} [1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] Was supported before this in Quirk Mode only.

更多

  • {{HTMLElement("html")}}
  • {{HTMLElement("head")}}

修订版来源

<p>{{HTMLRef}}</p>

<h2 id="摘要">摘要</h2>

<p><em>HTML 主体元素</em> (<strong>&lt;body&gt;</strong>) 表示的是HTML文档的主体内容,任何一个HTML文档,只允许存在一个&nbsp;&lt;body&gt; 元素。</p>

<ul class="htmlelt">
 <li><dfn><a href="/en-US/docs/Web/HTML/Content_categories">内容分类</a></dfn> <a href="/en-US/docs/Web/HTML/Sections_and_Outlines_of_an_HTML5_document#Sectioning_roots">Sectioning root</a>.</li>
 <li><dfn>许可内容</dfn> <a href="/en-US/docs/Web/HTML/Content_categories#Flow_content">Flow content</a>.</li>
 <li><dfn>标记省略</dfn>如果它的子元素不是空格、注释、{{HTMLElement("script")}} 元素或者&nbsp;{{HTMLElement("style")}}元素的话,可以省略开始标签。如果body元素有内容或者有开始标签,或者不是以注释结尾就可以省略结束标签。</li>
 <li><dfn>父级元素</dfn>body必须是{{HTMLElement("html")}} 的直接子元素 。</li>
 <li><dfn>DOM 接口</dfn> {{domxref("HTMLBodyElement")}}
  <ul>
   <li><code>&lt;body&gt;元素暴露在</code>{{domxref("HTMLBodyElement")}} 接口中。</li>
   <li>你可以通过&nbsp;{{domxref("document.body")}}&nbsp;属性来访问body元素。</li>
  </ul>
 </li>
</ul>

<h2 id="属性">属性</h2>

<p>该元素包含所有<a href="/en-US/docs/Web/HTML/Global_attributes">全局特性</a>。</p>

<dl>
 <dt>{{htmlattrdef("alink")}} {{obsolete_inline}}</dt>
 <dd>超链接被选中时的颜色。这个方法不符合标准,请用元素的<em>&nbsp;CSS&nbsp;{{cssxref(":active")}} 伪类的{{cssxref("color")}} 属性代替。</em>&nbsp;</dd>
 <dt>{{htmlattrdef("background")}} {{obsolete_inline}}</dt>
 <dd>将用URI地址指定的图片设置为背景。这个方法不符合标准,请用元素的&nbsp;<em>CSS {{cssxref("background")}} </em>属性代替。</dd>
 <dd>
 <div class="note"><strong>Note:</strong> Starting in Gecko 7.0 {{geckoRelease("7.0")}}, <code>background</code> is no longer resolved as a URI; instead, it's treated as a simple string.</div>
 </dd>
 <dt>{{htmlattrdef("bgcolor")}} {{obsolete_inline}}</dt>
 <dd>文档的背景颜色。这个方法不符合标准,请用<em>CSS {{cssxref("background-color")}} </em>属性代替。</dd>
 <dt>{{htmlattrdef("bottommargin")}} {{obsolete_inline}}</dt>
 <dd>body元素底部的空白。这个方法不符合标准,请用元素的&nbsp;<em>CSS {{cssxref("margin-bottom")}} </em>属性代替。</dd>
 <dt>{{htmlattrdef("leftmargin")}} {{obsolete_inline}}</dt>
 <dd>body元素左边的空白。这个方法不符合标准,请用元素的&nbsp;<em>CSS {{cssxref("margin-left")}} </em>属性代替。</dd>
 <dt>{{htmlattrdef("link")}} {{obsolete_inline}}</dt>
 <dd>未访问过的超链接的颜色。这个方法不符合标准,请用&nbsp;<em>CSS&nbsp;{{cssxref(":link")}} 伪类</em>的&nbsp;<em>{{cssxref("color")}} </em>属性代替。</dd>
 <dt>{{htmlattrdef("onafterprint")}} {{HTMLVersionInline(5)}}</dt>
 <dd>用户打印完成当前文档后的回调函数。</dd>
 <dt>{{htmlattrdef("onbeforeprint")}} {{HTMLVersionInline(5)}}</dt>
 <dd>用户请求打印当前文档时(打印前)的回调函数。</dd>
 <dt>{{htmlattrdef("onbeforeunload")}} {{HTMLVersionInline(5)}}</dt>
 <dd>当文档即将被卸载的回调函数。</dd>
 <dt>{{htmlattrdef("onblur")}} {{HTMLVersionInline(5)}}</dt>
 <dd>DOM失去焦点的回调函数。</dd>
 <dt>{{htmlattrdef("onerror")}} {{HTMLVersionInline(5)}}</dt>
 <dd>DOM加载失败的回调函数。</dd>
 <dt>{{htmlattrdef("onfocus")}} {{HTMLVersionInline(5)}}</dt>
 <dd>DOM接收到焦点focus的回调函数。</dd>
 <dt>{{htmlattrdef("onhashchange")}} {{HTMLVersionInline(5)}}</dt>
 <dd>当文档当前地址的片段标识部分(地址后面以#号开始的部分)变化时的回调函数。</dd>
 <dt>{{htmlattrdef("onlanguagechange")}} {{experimental_inline}}</dt>
 <dd>语言改变时的回调函数。</dd>
 <dt>{{htmlattrdef("onload")}} {{HTMLVersionInline(5)}}</dt>
 <dd>DOM完成加载的回调函数。</dd>
 <dt>{{htmlattrdef("onmessage")}} {{HTMLVersionInline(5)}}</dt>
 <dd>DOM接收到message的回调函数。</dd>
 <dt>{{htmlattrdef("onoffline")}} {{HTMLVersionInline(5)}}</dt>
 <dd>网络连接失败的回调函数。</dd>
 <dt>{{htmlattrdef("ononline")}} {{HTMLVersionInline(5)}}</dt>
 <dd>网络恢复连接的回调函数。</dd>
 <dt>{{htmlattrdef("onpopstate")}} {{HTMLVersionInline(5)}}</dt>
 <dd>用户导航历史会话的回调函数。</dd>
 <dt>{{htmlattrdef("onredo")}} {{HTMLVersionInline(5)}}</dt>
 <dd>Function to call when the user has moved forward in undo transaction history.</dd>
 <dt>{{htmlattrdef("onresize")}} {{HTMLVersionInline(5)}}</dt>
 <dd>DOM大小调整时触发的回调函数。</dd>
 <dt>{{htmlattrdef("onstorage")}} {{HTMLVersionInline(5)}}</dt>
 <dd>存储区改变的回调函数。</dd>
 <dt>{{htmlattrdef("onundo")}} {{HTMLVersionInline(5)}}</dt>
 <dd>Function to call when the user has moved backward in undo transaction history.</dd>
 <dt>{{htmlattrdef("onunload")}} {{HTMLVersionInline(5)}}</dt>
 <dd>当文档已经被关闭的回调函数。</dd>
 <dt>{{htmlattrdef("rightmargin")}} {{obsolete_inline}}</dt>
 <dd>body元素右边的空白。这个方法不符合标准,请用元素的&nbsp;<em>CSS {{cssxref("margin-right")}} </em>属性代替。</dd>
 <dt>{{htmlattrdef("text")}} {{obsolete_inline}}</dt>
 <dd>文本的颜色。这个方法不符合标准,请用元素的&nbsp;<em>CSS&nbsp;{{cssxref("color")}}属性代替。</em></dd>
 <dt>{{htmlattrdef("topmargin")}} {{obsolete_inline}}</dt>
 <dd>body元素顶部的空白。这个方法不符合标准,请用元素的&nbsp;<em>CSS {{cssxref("margin-top")}} </em>属性代替。</dd>
 <dt>{{htmlattrdef("vlink")}} {{obsolete_inline}}</dt>
 <dd>已访问的超链接的颜色。这个方法不符合标准,请用&nbsp;<em>CSS&nbsp;{{cssxref(":visited")}} 伪类</em>的&nbsp;<em>{{cssxref("color")}} </em>属性代替。</dd>
</dl>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG', 'sections.html#the-body-element', '&lt;body&gt;')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>Changed the list of non-conforming features.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', 'sections.html#the-body-element', '&lt;body&gt;')}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>Obsoleted the formerly deprecated attributes. Defined the behavior of the non-conforming and never standardized <code>margintop</code>, <code>marginleft</code>, <code>marginright</code> and <code>marginbottom</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML4.01', 'struct/global.html#h-7.5.1', '&lt;body&gt;')}}</td>
   <td>{{Spec2('HTML4.01')}}</td>
   <td>Deprecated the <code>alink</code>, <code>background</code>, <code>bgcolor</code>, <code>link</code>, <code>text</code> and <code>vlink</code> attributes.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>特性</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>支持</td>
   <td>1.0</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>onlanguagechange</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("32")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>bottommargin</code>, <code>leftmargin</code>, <code>rightmargin</code>, <code>topmargin</code> {{obsolete_inline}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop("35")}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>特性</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>支持</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>onlanguagechange</code></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("32")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>bottommargin</code>, <code>leftmargin</code>, <code>rightmargin</code>, <code>topmargin</code> {{obsolete_inline}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("35")}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Was supported before this in Quirk Mode only.</p>

<h2 id="更多">更多</h2>

<ul>
 <li>{{HTMLElement("html")}}</li>
 <li>{{HTMLElement("head")}}</li>
</ul>
恢复到这个版本