【发布时间】:2017-11-14 14:11:18
【问题描述】:
我有一个post() 调用绑定到一组图像的click() 方法。
在post() 调用中,我可以引用jQuery(this) 并通过它访问原始对象。 (例如数据参数,或更改其状态):
jQuery('.vote .magic_button').click(function() {
jQuery.post(url, {
action: 'ajax_vote',
'vote_target': jQuery(this).data('postid')
})
.done(function(data) {
// $img = jQuery(this).find('img');
})
});
当 AJAX 调用返回时,在验证响应后,我想引用最初单击的图像,但在这个新上下文中不再是 this。
如何在不必将信息传回 data 参数内的情况下访问它?
【问题讨论】:
标签: javascript jquery ajax