คุณสมบัติ type ของ HTML DOM Ol (Ordered List) ใช้สำหรับ อ่านหรือกำหนด ค่าของแอตทริบิวต์ type ซึ่งกำหนดประเภทของเครื่องหมายลำดับ (marker) ในรายการลำดับ
ไวยากรณ์ (Syntax)
การอ่านค่า
olObject.type
การกำหนดค่า
olObject.type = '1|a|A|i|I'
ค่าที่เป็นไปได้
| ค่า (Value) | คำอธิบาย |
|---|---|
1 | ตัวเลข (1, 2, 3...) - ค่าเริ่มต้น |
a | ตัวอักษรพิมพ์เล็ก (a, b, c...) |
A | ตัวอักษรพิมพ์ใหญ่ (A, B, C...) |
i | เลขโรมันพิมพ์เล็ก (i, ii, iii...) |
I | เลขโรมันพิมพ์ใหญ่ (I, II, III...) |
ตัวอย่างการใช้งาน
ตัวอย่างนี้เปลี่ยนเครื่องหมายลำดับจากตัวเลขเป็นเลขโรมันพิมพ์ใหญ่ (I, II, III...)
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Ol type</title>
<style>
form { width:70%; margin: 0 auto; text-align: center; }
* { padding: 2px; margin:5px; }
input[type="button"] { border-radius: 10px; }
ol{ width: 30%; margin: 0 auto; }
</style>
</head>
<body>
<form>
<fieldset>
<legend>HTML-DOM-Ol-type</legend>
<h3>Students</h3>
<ol id="orderList" type='2'>
<li>Adam</li>
<li>Alex</li>
<li>Bina</li>
<li>Eden</li>
<li>Rajesh</li>
<li>Zampa</li>
</ol>
<input type="button" onclick="changeMarker()" value="Change Marker">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var studentList = document.getElementById("orderList");
function changeMarker() {
studentList.type = 'I';
divDisplay.textContent = 'Marker Changed';
}
</script>
</body>
</html>
ผลลัพธ์ (Output)
ก่อนกดปุ่ม "Change Marker":

หลังกดปุ่ม "Change Marker":
