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.

Document.createTextNode()

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

創建一個新的文字節點.

Syntax

var text = document.createTextNode(data);
  • 文字屬於一個文字節點.
  • 將含有數據的串加入文字節點中.

Example

<!DOCTYPE html>
<html lang="en">
<head>
<title>createTextNode example</title>
<script>
function addTextNode(text) {
  var newtext = document.createTextNode(text),
      p1 = document.getElementById("p1");

  p1.appendChild(newtext);
}
</script>
</head>

<body>
  <button onclick="addTextNode('YES! ');">YES!</button>
  <button onclick="addTextNode('NO! ');">NO!</button>
  <button onclick="addTextNode('WE CAN! ');">WE CAN!</button>

  <hr />

  <p id="p1">First line of paragraph.</p>
</body>
</html>

Specifications

Specification Status Comment
Document Object Model (DOM) Level 3 Core Specification
The definition of 'Document.createTextNode()' in that specification.
Recommendation No change
Document Object Model (DOM) Level 2 Core Specification
The definition of 'Document.createTextNode()' in that specification.
Recommendation Initial definition

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) (Yes) (Yes) ?
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support ? ? ? ? ?

文件標籤與貢獻者

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