Jquery 类 - 向其添加增量 [英] Jquery Class - Add An Increment To It

查看:25
本文介绍了Jquery 类 - 向其添加增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Jquery 的myclass"末尾添加一个动态生成的数字.所以我希望它在最后增加一个数字,如下所示:

I am trying to add a dynamically-generated number at the end of "myclass" in Jquery. So I want it to increment a number at the end like this:

我的班级1

我的班级2

我的班级3

我的班级4

我尝试了几次,但不知道我在做什么.任何帮助都会很棒!

I've tried a few times but have no clue what I'm doing. Any help would be great!

  var f=1;for(var g=0;g<d.count;g++)for(var f=1; f<3; f++){e.append("<li class='myclass"+f+"'><a>"+f+"</a></li>");f++}

推荐答案

我不确定您要做什么,但这是我的看法.当然,你可以更具体的 jQuery 选择器.

I am not sure what you are trying to do, but here's my take on it. Of course, you can be more specific on the jQuery selector.

var i = 1;
$('li').each(function(){
    $(this).addClass('myclass'+i);
    i++;
});

编辑

根据提供的代码:

for(var f = 1; f < 5; f++){
    e.append("<li class='myclass"+f+"'><a>"+f+"</a></li>");
    f++;
}

这篇关于Jquery 类 - 向其添加增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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