how to make jquery each a number

后端 未结 3 1124
南笙
南笙 2021-02-08 15:26

This is my code:

$.each(3, function(n) {
    alert(n);
});

I want to alert three times but it doesn\'t work. What can I do?

3条回答
  •  后悔当初
    2021-02-08 15:33

    You can't.
    $.each can only iterate over arrays or objects. You're looking for the for loop:

    for(var n = 0; n < 5; n++) {
        alert(n);
    }
    

提交回复
热议问题