$(document).ready(function() {
$('.raj').click(function() {
if (!$(this).hasClass('already')) {
$('.infos').html('');
$('.infos').hide("fast");
$.ajax({
type: "POST",
dataType: "json",
url: "ggg/hhh/rrr.php",
success: function (msg) {
$('.infos').html(msg['ats']);
arr = msg['valid'];
}
});
$('.infos').show("slow");
if (arr == 1) {
$(this).css("cursor", "default");
$(this).addClass('already');
$(this).animate({
opacity: 0.1
}, 1000);
}
}
})
})
当我点击类raj
(它是一个图像)的元素,没有任何反应。只有第二次点击后,我的事件才会发生。这是为什么发生?为什么我的活动不是第一次开火?
编辑: 这部分F * cked起来:
if(arr == 1)
{
$(this).css("cursor", "default");
$(this).addClass('already');
$(this).animate({
opacity: 0.1
}, 1000);
}
但msg['valid']
真的是始终为1,所以我不明白这一点。
试试吧,但是结果的处理必须在ajax调用返回在结果实际完成前你已经检查过结果 – Vinzenz 2010-10-13 21:42:53
@Vinzenz:为什么这里不行'$(this)',我们必须使用'thisObj'? – 2010-10-13 21:44:57
+1另一件需要记住的事情是'$ .ajax'有一个'context:'属性,你可以在回调中设置'this'的值,所以你可以添加'context:this',让'this'引用回调中的元素。 – user113716 2010-10-13 21:48:38