$('check1')。attr('checked','true')在ajax成功函数中不起作用

时间:2014-02-26 11:41:05

标签: javascript ajax

请告诉我问题的解决方案:

$('#check0').attr('checked','true');   //it work
var idx=12;
$.ajax({
   type: 'POST',
   url: 'get_list.php',
   data: 'id='+idx,
   cache: false,
   success: function(){
       alert('success');     //it work fine
       $('#check1').attr('checked','true');   //not work
       $('#no1').val('222222');    //it work too
   }
});

我尝试将$ ('check1'). attr ('checked', 'true')放到ajax函数成功但不幸的是不能正常工作,但是如果我把代码放在ajax函数之外它工作正常....上面的代码可能有问题?

为什么只有复选框不起作用? ..虽然警报和传递文本到文本输入工作正常,我确信check1确实存在..它使我已经2小时停止工作..

2 个答案:

答案 0 :(得分:0)

你的ajax的成功方法没有被执行,你的代码还可以。检查这个小提琴,看看结果。

http://jsfiddle.net/U4wS4/1/

$('#check0').attr('checked',true);   //it work
var idx = 12;
$.ajax({
   type: 'POST',
   data: 'id='+idx,
   success: function(){
       $('#check1').attr('checked',true);   //not work
   }
});

答案 1 :(得分:-1)

在ajax成功中你正在使用

$('#check1')

你还没有发布你的HTML但是我觉得你想在ajax成功函数中使用它

$('#check0')