如果没有收集,jQuery可以替代经典的for循环 [英] JQuery alternative to classic for-loop if not collection
本文介绍了如果没有收集,jQuery可以替代经典的for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我要遍历不是集合的内容,可以在JavaScript中使用for循环.因此,要提醒第0-9天的数字:
If I want to loop over something that is not a collection I may use a for-loop in JavaScript. So to alert day numbers 0-9:
var days = 10;
for(var i = 0; i < days; i++)
alert(i);
但是执行这样的for循环的JQuery方法是什么(假设我不能使用$ each,因为它不是一个集合)?
But what would be the JQuery way of doing such a for-loop (assuming I can't use $each, as it's not a collection)?
推荐答案
jQuery.each效果很好
jQuery.each works just fine
$.each([ 52, 97 ], function( index, value ) {
alert( index + ": " + value );
});
但是说实话,对于您似乎要问的问题,香草JavaScript要好得多
But honestly, vanilla JavaScript is much better for what you seem to be asking
这篇关于如果没有收集,jQuery可以替代经典的for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文