如何透過 JavaScript 設定列表項標記型別?


要設定列表項標記型別的型別,請使用 listStyleType 屬性。標記型別可以是方塊、圓形、字典等。

範例

你可以嘗試執行以下程式碼,透過 JavaScript 設定列表項標記型別 −

即時演示

<!DOCTYPE html>
<html>
   <body>
      <ul id="myID">
         <li>One</li>
         <li>Two</li>
      </ul>
      <button type="button" onclick="displaySquare()">Update list style type (square)</button>
      <button type="button" onclick="displayDecimal()">Update list style type (decimal)</button>
      <script>
         function displaySquare() {
            document.getElementById("myID").style.listStyleType = "square";
         }
         function displayDecimal() {
            document.getElementById("myID").style.listStyleType = "decimal";
         }
      </script>
   </body>
</html>

更新於:23-06-2020

378 次瀏覽

開啟你的 職業

透過完成課程獲得認證

開始使用
廣告
© . All rights reserved.