คุณสมบัติประเภทวัตถุ HTML DOM ใช้เพื่อตั้งค่าหรือส่งคืนค่าของแอตทริบิวต์ประเภทของวัตถุ อย่างไรก็ตาม แอตทริบิวต์ type ใช้เพื่อกำหนดประเภทสื่อเหมือนกับวัตถุ
ต่อไปนี้เป็นไวยากรณ์การตั้งค่าคุณสมบัติประเภท -
obj.type = type_of_media
ด้านบน type_of_media เป็นประเภทสื่อมาตรฐาน เช่น image/bmp, image/tiff, image/tff เป็นต้น
ต่อไปนี้คือไวยากรณ์ที่จะส่งคืนคุณสมบัติประเภท -
obj.type
ให้เราดูตัวอย่างการใช้คุณสมบัติประเภทวัตถุ DOM -
ตัวอย่าง
<!DOCTYPE html>
<html>
<body>
<object id="obj" width="450" height="200"
data="https://www.tutorialspoint.com/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> ผลลัพธ์

คลิกปุ่มเพื่อแสดงประเภท -
