HTML DOM 物件型別屬性


HTML DOM 物件型別屬性用於設定或返回物件 type 屬性的值。但是,type 屬性用於設定諸如物件之類的媒體型別。

以下是設定 type 屬性的語法 -

obj.type = type_of_media

在此,type_of_media 是標準媒體型別,例如 image/bmp、image/tiff、image/tff,等等。

以下是返回 type 屬性的語法 -

obj.type

現在,讓我們看一個實現 DOM 物件 type 屬性的例子 -

示例

 即時演示

<!DOCTYPE html>
<html>
<body>
<object id="obj" width="450" height="200"
data="https://tutorialspoint.tw/flex/samples/CSSApplication.swf"
type="application/vnd.adobe.flash-movie"></object>
<button onclick="display()">Display the media type</button>
<p id="pid"></p>
<script>
function display() {
   var x = document.getElementById("obj").type;
      document.getElementById("pid").innerHTML = x;
}
</script>
</body>
</html>

輸出

點選按鈕以顯示型別 -

更新於: 30-Jul-2019

125 次瀏覽

Kickstart Your 事業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.