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