Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

HTML DOM Meter Object


HTML DOM Meter Object ใน HTML แทนองค์ประกอบ <meter>

หมายเหตุ: อย่าใช้ <meter> เป็น progress bar แต่ใช้เป็น gauge (วัดค่า) เท่านั้น

ไวยากรณ์ (Syntax)

การสร้างองค์ประกอบ <meter>:

var meterObject = document.createElement("METER")

ที่นี่ "meterObject" สามารถมีคุณสมบัติดังต่อไปนี้:

คุณสมบัติ คำอธิบาย
high ตั้งค่า/ส่งคืนค่าของแอตทริบิวต์ high ใน gauge
labels ส่งคืนรายการของ <label> elements ที่เป็น label สำหรับ gauge
low ตั้งค่า/ส่งคืนค่าของแอตทริบิวต์ low ใน gauge
max ตั้งค่า/ส่งคืนค่าของแอตทริบิวต์ max ใน gauge
min ตั้งค่า/ส่งคืนค่าของแอตทริบิวต์ min ใน gauge
optimum ตั้งค่า/ส่งคืนค่าของแอตทริบิวต์ optimum ใน gauge
value ตั้งค่า/ส่งคืนค่าของแอตทริบิวต์ value ใน gauge

ตัวอย่างการใช้งาน

<!DOCTYPE html> <html> <head> <title>Meter value</title> <style> 
    form { 
        width: 70%; 
        margin: 0 auto; 
        text-align: center; 
    } 
    * { 
        padding: 2px; 
        margin: 5px; 
    } 
    input[type="button"] { 
        border-radius: 10px; 
    } 
</style> </head> <body> 
    <form> 
        <fieldset> 
            <legend>Meter-value</legend> 
            <label for="paulaLifeSource">Paula's Health Risk: </label> 
            <meter id="paulaLifeSource" max="100" min="0" high="80" value="75" low="70" value="85"> 
            </meter> 
            <input type="button" onclick="lifeSource()" value="Reduce"> 
            <div id="divDisplay"></div> 
        </fieldset> 
    </form> 
    <script> 
        var divDisplay = document.getElementById("divDisplay"); 
        divDisplay.textContent = 'Life Source at ' + paulaLifeSource.value; 
        function lifeSource(effect) { 
            var paulaLifeSource = document.getElementById("paulaLifeSource"); 
            var Immunity = paulaLifeSource.value; 
            paulaLifeSource.value = 10; 
            divDisplay.textContent = 'value changed to ' + paulaLifeSource.value + ' from ' + Immunity; 
        } 
    </script> 
</body> </html>

ผลลัพธ์

ก่อนคลิกปุ่ม 'Reduce':

HTML DOM Meter Object

หลังคลิกปุ่ม 'Reduce':

HTML DOM Meter Object