HTML DOM li value 屬性


Li value 屬性返回/設定 <li> 元素 value 屬性的值。

語法

以下是語法 -

  • 返回值為 <li> value 屬性
liObject.value
  • 設定 <li> 屬性 value 的值
liObject.value = ‘string’

我們來看一個 Li value 屬性的例子 -

示例

 簡報

<!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’ 按鈕之前 -

選中 ‘What exams are in this week?’ 按鈕之後 -

更新於: 2019-07-30

113 次瀏覽

開始你的 職業生涯

完成課程並獲得認證

開始
廣告
© . All rights reserved.