คุณสมบัติ max ของ HTML DOM Progress ใช้สำหรับคืนค่าและเปลี่ยนค่าของแอตทริบิวต์ max ขององค์ประกอบ progress ในเอกสาร HTML
รูปแบบไวยากรณ์ (Syntax)
1. การคืนค่า max
object.max
2. การเปลี่ยนแปลง max
object.max = “number”
ตัวอย่าง
ตัวอย่างการใช้งานคุณสมบัติ max ของ progress:
<!DOCTYPE html> <html> <head> <style> html{ height:100%; } body{ text-align:center; color:#fff; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat; height:100%; } p{ font-weight:700; font-size:1.2rem; } .drop-down{ width:35%; border:2px solid #fff; font-weight:bold; padding:8px; } .btn{ background:#0197F6; border:none; height:2rem; border-radius:2px; width:35%; margin:2rem auto; display:block; color:#fff; outline:none; cursor:pointer; } .show{ font-size:1.5rem; font-weight:bold; } </style> </head> <body> <h1>ตัวอย่างคุณสมบัติ DOM Progress max</h1> <p>สถานะงานที่ค้าง:</p> <p>(สีฟ้า = เสร็จแล้ว & สีขาว = ค้าง)</p> <progress value="20" max="100" class="progress"></progress> <button onclick="changeMax()" class="btn">เปลี่ยน Max = 200</button> <div class="show"></div> <script> function changeMax() { var progress = document.querySelector(".progress"); var msg = document.querySelector(".show"); msg.innerHTML = "ค่า max เดิมคือ " + progress.max +''; progress.max="200"; msg.innerHTML += " ค่า max ใหม่คือ " + progress.max+"";
} </script> </body> </html>
ผลลัพธ์
โค้ดด้านบนจะให้ผลลัพธ์ดังนี้:

คลิกปุ่ม 「เปลี่ยน Max=200」 เพื่อเปลี่ยนค่าของแอตทริบิวต์ max ของแถบความคืบหน้า
