使用document.write()在JavaScript中创建有序列表的问题
解决方法
你的代码只输出了列表项<li>,但有序列表需要用<ol>标签包裹所有列表项,浏览器才会渲染出编号样式。
修正后的代码如下:
<script> // Create ordered list document.write("<ol>"); document.write("<li> Reduce spending on non-necessities.</li>"); document.write("<li> Use extra money to pay off debt. Starting with highest-interest credit cards.</li>"); document.write("<li> Continue paying off debts until you are debt free.</li>"); document.write("<li> Put a fixed percent of your pay aside every payday.</li>"); document.write("</ol>"); </script>
说明:
<ol>是有序列表的容器标签,所有<li>必须放在<ol>的起始标签<ol>和结束标签</ol>之间,浏览器会自动为列表项添加连续编号。- 若需要无序列表(圆点样式),才会用
<ul>标签包裹<li>,你的需求是编号展示,因此必须使用<ol>。
内容的提问来源于stack exchange,提问作者Maya Strickland
相关产品推荐
相关产品推荐

