我已经编写了这段代码,这是 jquery 中的一个基本图片库
$(document).ready(function() {
setInterval("rotateImages()",2000)
})
function rotateImages() {
var curPhoto = $("#photoshow div.current");
var nextPhoto = curPhoto.next();
if (nextPhoto.length == 0) {
nextPhoto = $("#photoshow div:first");
}
curPhoto.removeClass("current").addClass("previous");
nextPhoto.css({
opacity: 0.0
}).addClass("current").animate({
opacity: 1.0
}, 1000, function () {
curPhoto.removeClass("previous")
});
}
这有效,除非我用 {} 包装 if 语句,但它没有。我只是想了解两者之间的区别以及为什么它不起作用。