编辑 - 香港专业教育学院改变了我的代码:jQuery语法错误? CSS和动画的 '如果' 和 '其他' 语句
这工作得很好:
$(".image-div").click(function() {
if ($(this).css('z-index') == 1)
$(this).css('z-index','2');
else
$(this).css('z-index','1');
});
而且这也适用:
$(".image-div").click(function() {
if ($(this).css('z-index') == 1)
$(this).animate({
width: '500px'
}, 5000, function() {
// Animation complete.
});
else
$(this).animate({
width: '250px'
}, 5000, function() {
// Animation complete.
});
});
但这不要做任何事情:
$(".image-div").click(function() {
if ($(this).css('z-index') == 1)
$(this).css('z-index','2');
$(this).animate({
width: '500px'
}, 5000, function() {
// Animation complete.
});
else
$(this).css('z-index','1');
$(this).animate({
width: '250px'
}, 5000, function() {
// Animation complete.
});
});
谢谢
检查是否关闭和以及关闭匿名函数 – Someone 2011-06-08 19:26:50