You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 14:01:12