【发布时间】:2010-11-24 12:01:06
【问题描述】:
我已经使用 $.each 进行迭代有一段时间了,但我不断听到人们说要使用原生 JS 来进行循环。我非常关心性能,但我不确定是否总是可以以有意义的方式将 $.each 替换为 for。
所以我的问题是,是否可以始终将 $.each 替换为 for,如果不是,那么经验法则是什么时候可以做到,什么时候不能做到。
我有一个这样的:
$this.find("div.class").each(function (){
var $thisparent = $(this).parent();
if (condition) {
$(this).prepend($thisparent.text());
}
if (condition2) {
$(this).prepend($thisparent.text());
}
});
【问题讨论】:
标签: javascript jquery for-loop each