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

HTML DOM li ค่าคุณสมบัติ


คุณสมบัติค่า Li ส่งกลับ/ตั้งค่าของแอตทริบิวต์ค่าขององค์ประกอบ

  • ไวยากรณ์

    ต่อไปนี้เป็นไวยากรณ์ -

    • คืนค่าของ
    • ค่า คุณลักษณะ
    liObject.value
    • คุณค่าของ
    • ชุดค่าแอตทริบิวต์
    liObject.value = ‘string’

    ให้เราดูตัวอย่างสำหรับ ค่า Li ทรัพย์สิน −

    ตัวอย่าง

    <!DOCTYPE html>
    <html>
    <head>
    <title>HTML DOM value</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-value</legend>
    <h3>Race Result</h3>
    <ol id="race">
    <li>Alex</li>
    <li>Eden</li>
    <li>Samuel</li>
    <li>Zampa</li>
    </ol>
    <input type="button" onclick="rectifyResult()" value="Alex Cheated">
    <div id="divDisplay"></div>
    </fieldset>
    </form>
    <script>
       var divDisplay = document.getElementById("divDisplay");
       var studentList = document.getElementsByTagName("li");
       var race = document.getElementById("race");
       function rectifyResult() {
          studentList[1].value = '1';
          studentList[2].value = '2';
          studentList[3].value = '3';
          race.removeChild(studentList[0])
          divDisplay.textContent = 'Alex is disqualified';
       }
    </script>
    </body>
    </html>

    ผลลัพธ์

    สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

    ก่อนคลิก 'Alex Cheated' ปุ่ม −

    HTML DOM li ค่าคุณสมบัติ

    หลังจากตรวจสอบ 'สัปดาห์นี้มีสอบอะไรบ้าง' ปุ่ม −

    HTML DOM li ค่าคุณสมบัติ