首页 > 测试使用setInterval的时候,一直提醒我没有nextImg()方法

测试使用setInterval的时候,一直提醒我没有nextImg()方法

$(document).ready(function() {
function nextImg(){
active = $('.slide .active').removeClass('active').hide;
if(typeof(active.next('div')) != undefined)
{
active.next('div').addClass('active').show();
}else{
$('.slide .first').addClass('active').show();
}
}

$('.slide .first').addClass('active').show();

setInterval("nextImg()",1000);

});


你这种写法,setInterval只会去global作用域找nextImg方法,当然是undefined
改成setInterval(nextImg, 1000);

还有hide是个方法
active = $('.slide .active').removeClass('active').hide();

【热门文章】
【热门文章】