LI的数字使用jQuery [英] Number LI's using jQuery

查看:89
本文介绍了LI的数字使用jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有序列表,但我想编号是在单独的span标记中手动进行的,而不是使用默认的list-style: decimal;

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>

如何使用jQuery实现此目标?

How can I achieve this using jQuery?

非常感谢!

推荐答案

$(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; }

根据需要进行调整.

这篇关于LI的数字使用jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆