當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


HTML DOM small用法及代碼示例

HTML DOM 小對象與 HTML <small> 元素相關聯。我們可以分別使用 createElement() 和 getElementById() 方法創建和訪問小元素。

用法

以下是語法 -

創建一個小對象 -

var s= document.createElement("SMALL");

示例

讓我們看一個小物體的例子 -

<!DOCTYPE html>
<html>
<body>
<h1>Small object example</h1>
<p>Create a small element containing some text by clicking the below button</p>
<button onclick="CreateSmall()">CREATE</button>
<p>This is normal text</p>
<script>
   function CreateSmall() {
      var s = document.createElement("SMALL");
      var txt = document.createTextNode("This is small text");
      s.appendChild(txt);
      document.body.appendChild(s);
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 -

單擊“創建”按鈕 -

相關用法


注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 HTML DOM small object。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。