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

查看:96
本文介绍了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:

myclass1

myclass2

myclass3

myclass4

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

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天全站免登陆