开发者

Number LI's using jQuery

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

<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!


$(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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜