如何使用 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>

更新於: 2020 年 6 月 23 日

378 次瀏覽

開啟你的 職業 生涯

完成課程,獲得認證

開始學習
廣告