control_td.each(function(){
$.ajax({
url: 'control.php?udid='+$(this).attr('udid'),
cache: false,
async: true
}).done(function(data) {
$(this).html(data);
});
});
但$this
在.done
子功能中不起作用。我在这做错了什么?
答案 0 :(得分:6)
因为this
没有引用回调中的元素项。
尝试以新值结束。
control_td.each(function(){
var $self = $(this); // magic here!
$.ajax({
url: 'control.php?udid='+$(this).attr('udid'),
cache: false,
async: true
}).done(function(data) {
$self.html(data);
});
});
答案 1 :(得分:4)
试试这个:
control_td.each(function () {
var $this = $(this);
$.ajax({
url: 'control.php?udid=' + $this.attr('udid'),
cache: false,
async: true
}).done(function (data) {
$this.html(data);
});
});
答案 2 :(得分:3)
您还可以设置context
的{{1}}选项, check this option 。
$.ajax