how to make jquery each a number

后端 未结 3 1133
南笙
南笙 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:47

    each must operate on an object. Try to create an array of length 3, e.g.

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

    Of course, I don't see the reason to avoid normal Javascript.

    for (var n = 0; n < 3; ++ n)
       alert(n);
    

提交回复
热议问题