且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在JQuery中将不同的类添加到同一类?

更新时间:2023-12-02 23:14:10

现在我终于明白了你想要什么

Now I finnaly understand what you want

此代码是必需的

// Wait on the document to be loaded
$(function(){
    // get every element with the class example in an array and loop
    // through it(each) with i  as index
    $(".example").each(function(i){
        // add class ex with the index
        // this is the element we are pointing at so a div
        $(this).addClass("ex" + i);
    });
});​

但是当您通过5个div遍历数组时,您可以在服务器端轻松做到这一点;)

but you could do this easily on server side when you loop through your array with 5 divs ;)