用jQuery生成无序列表 [英] Generating an unordered list with jQuery

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

问题描述

有无序列表,在IE6-7中无法正常运行,我想通过jQuery函数替换.

There is unordered list, which not works properly in IE6-7, I would like want to replace it by a jQuery function.

所以,我们有:

  • 带有特殊#id(ul id =")的简单列表
  • 一些<li>标签
  • <li>中的一些特殊标记,用于显示行号(或您希望的其他名称).
  • simple list with special #id (ul id="")
  • some <li> tags
  • some special tag in <li> to show the number of a row (or something else, as you wish).

我需要一个函数,该函数将从无序列表的开始到末尾为每一行提供唯一的编号. (ul)

I need a function which will give an unique number for each row, from the beginning to the end of our unordered list. (ul)

推荐答案

<ul><li>test</li><li>test</li><li>test</li><li>test</li><li>test</li><li>test</li><li>test</li></ul>

$(document).ready(function(){   
    var increment=3;
    var start=8;
    $("ul").children().each(function(i) {
        $(this).prepend('<tag>'+(start+i*increment).toString()+'.</tag>');
    });
});

结果:

* 8. test
* 11. test
* 14. test
* 17. test
* 20. test
* 23. test
* 26. test

无增量且较短:

$(document).ready(function(){   
    $("ul").children().each(function(i) {
        $(this).prepend('<b>'+(1+i).toString()+'.</b> ');
    });
});

这篇关于用jQuery生成无序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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