【发布时间】:2011-08-12 16:08:58
【问题描述】:
我已经写了这段代码,这是一个 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 语句,但它不起作用。我只是想了解两者之间的区别以及为什么它不起作用。
【问题讨论】:
-
因为您可能错误地放置了括号...您是否收到任何 javascript 错误?
-
你把花括号放在哪里了?
-
不客气。但重要的是你在未来(在 Stackoverflow 和其他地方)更清楚地表达你的问题,因此我认为你得到了反对票......
-
@mustafa:请删除您的评论。已更新您的代码
-
抱歉 Naveen 感谢您为我编辑 :)
标签: javascript jquery if-statement curly-braces