HTML DOM 快速導覽 - 元素物件 <command> (HTMLCommandElement)

<command> 為 HTML 5 的互動式元素 (interactive elements) , DOM 介面為 HTMLCommandElement 。



取得 <command> 的元素物件 (object) 後,可存取元素的全域屬性 (global attribute) 。 HTMLCommandElement 另有定義屬性
  • type
  • label
  • icon
  • disabled
  • checked
  • radiogroup


這些都對應到 <command> 相同名稱的屬性。舉例如下
function run() {
    var d = document.getElementsByTagName("command");
    var s = document.getElementById("show");
    s.innerHTML = d[0];
}

/* 《程式語言教學誌》的範例程式
     http://pydoing.blogspot.com/
     檔名:htmldemo144.js
     功能:示範 JavaScript 程式 
     作者:張凱慶
     時間:西元 2011 年 8 月 */


此例用 document 物件的 getElementsByTagName() 方法 (method) ,取得標籤名稱為 command 的 HTMLCollection 物件,文件的第一個 <command> 元素亦即該 HTMLCollection 索引值為 0 的物件
var d = document.getElementsByTagName("command");
var s = document.getElementById("show");
s.innerHTML = d[0];


然後將 id 屬性為 show 的元素中顯示 d[0] 。


我們以下面的 HTML 文件載入
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM DEMO</title>
<script src="htmldemo144.js" type="text/javascript"></script>
</head>
<body>
<div>
<menu type="toolbar">
<command type="command" label="command1" onclick="save()">Command1</command>
<command type="command" label="command2" onclick="save()">Command2</command>
<command type="command" label="command3" onclick="save()">Command3</command>
</menu>
</div>
<input type="button" value="RUN" onclick="run();">
<div>Result: <span id="show"></span></div>
</body>
</html>

<!-- 《程式語言教學誌》的範例程式
     http://pydoing.blogspot.com/
     檔名:htmldemo144.html
     功能:示範 JavaScript 程式 
     作者:張凱慶
     時間:西元 2011 年 8 月 -->


瀏覽器 (browser) 開啟,按 RUN 後如下



由結果可看出,目前 Firefox 尚未建置 <summary> 。


中英文術語對照
互動式元素interactive elements
物件object
全域屬性global attribute
方法method
屬性attribute
瀏覽器browser


您可以繼續參考
HTML 5 範例

HTML 元素物件


相關目錄
HTML DOM 快速導覽
JavaScript 教材
首頁


參考資料
https://developer.mozilla.org/en/HTML/Element/command
http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#the-command-element

沒有留言: