好的,这是我的jQuery:
$.ajax({ type: "POST", url: $(this).attr('href') }).done(function( msg ) { $(this).parent().closest('p').html('Image Removed'); });
这是我的HTML:
foreach($galleryImages as $image) { ?> } ?>
自数据库更改以来,ajax工作正常.但是,完成功能无法正常工作.
我提醒了$(this).parent().closest('p').html()
它,它会提醒div当前的html.但是,它不会覆盖我正在输入的'Image Removed'.
this
在done函数内部不是元素,因为有一个新的函数范围
var elem = this; $.ajax({ type: "POST", url: $(this).attr('href') }).done(function( msg ) { // new function scope, "this" is now the XHR function $(elem).parent().closest('p').html('Image Removed'); });