Number LI's using jQuery

旧城冷巷雨未停 提交于 2019-12-19 11:40:37

问题


I have an ordered list, but I want to number is manually in a separate span tag than use the default list-style: decimal;

<ol>
 <li><span>1</span> item 1</li>
 <li><span>2</span> item 2</li>
</ol>

How can I achieve this using jQuery?

Many thanks!


回答1:


$(function() {
  $("ol > li").each(function(i, n) {
    $(this).prepend("<span>" + (i+1) + "</span> ");
  });
});

You'll need to disable the standard markers too:

ol { list-style-type: none; }

Adjust as required.



来源:https://stackoverflow.com/questions/1571024/number-lis-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!