Document.body

翻譯不完整。請協助 翻譯此英文文件

回傳目前文件的 <body><frameset> 節點,如元素不存在則回傳 null

語法

var objRef = document.body; 
document.body = objRef;

範例

// in 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"

備註

document.body is the element that contains the content for the document. In documents with <body> contents, returns the <body> element, and in frameset documents, this returns the outermost <frameset> element.

Though body is settable, setting a new body on a document will effectively remove all the current children of the existing <body> element.

規範

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'Document.body' in that specification.
Living Standard  
HTML 5.1
The definition of 'Document.body' in that specification.
Recommendation  
HTML5
The definition of 'Document.body' in that specification.
Recommendation  
Document Object Model (DOM) Level 2 HTML Specification
The definition of 'Document.body' in that specification.
Recommendation  
Document Object Model (DOM) Level 1 Specification
The definition of 'Document.body' in that specification.
Recommendation Initial definition.

瀏覽器相容性

  
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1 (Yes) 2 6 9.6 (possibly earlier) 4 (possibly earlier)
  
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) 5 (probably earlier)

參見

文件標籤與貢獻者

 此頁面的貢獻者: jackblackevo
 最近更新: jackblackevo,