var start = args.current - 2,end = args.current + 2;
if((start > 1 && args.current < 4)||args.current == 1){
end++;
}
if(args.current > args.pageCount-4 && args.current >= args.pageCount){
start--;
}
for (;start <= end; start++) {
if(start <= args.pageCount && start >= 1){
if(start != args.current){
_this.append('<a href="javascript:;" class="page" id="page">'+ start +'</a>');
}else{
_this.append('<a class="current" id="current">'+ start +'</a>');
}
}
}
请问这个for格式循环怎么理解?
就是普通的for循环啊,for循环不是块级作用域,用var声明变量时,在for循环外先声明跟在for的第一条语句中声明是一样的效果,所以你这个相当于把for的第一条语句提到for外面了,因为在for循环之前还要对声明的变量进行处理,如果没有那2个if,就可以直接写成
for (var start = args.current - 2,end = args.current + 2;start <= end; start++) {}