当 $.each() 第一次循环时,我有不同的代码,但随后我的代码将与循环结束时相同。
最佳答案
each()
函数有 2 个参数,分别为 index
和 Element
对每个匹配元素执行的函数。
您可以尝试下面的代码
$( "li" ).each(function( index ) {
if(index == 0){
// loop for the first time
}
else{
// will run for all iteration but first
}
});
关于javascript - 如何在第一次运行 $.each() 时使用不同的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43511967/