我想在AJAX PHP腳本完成時移除父div。問題是,當你的PHP腳本是jQuery無法刪除div。jQuery未能移除父div
有人知道我的代碼錯誤在哪裏,爲什麼我不能使用我提供的方法刪除想要的DIV?
這裏是代碼:
HTML:
<div id="newTask">
<input type="hidden" id="taskID" 1="" name="taskID" value="39">
<input type="text" id="taskName1" name="taskName1" value="12">
<span class="remove" onclick="removeDIVS(39);"></span>
</div>
JS:
function removeDIVS(currentID){
$.ajax({
url: 'scripts/removeTask.php',
type: 'post',
data: 'id='+currentID,
success: function(data, status) {
if(data == "OK") {
$(this).parent().remove();
}
else{
$('#TaskResult').html(data);
}
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError:" + err);
}
}); // end ajax call
}
$(本).parent()刪除(); - $(this)不是你可能期望的span元素 – GRSEV 2014-12-13 14:07:07
可能是因爲'$(this)'沒有引用你想要的div。用'$(「#newTask).remove()'替換'$(this).parent()。remove()'確認 – haxtbh 2014-12-13 14:07:14
'this'指向'window'。 – 2014-12-13 14:07:14