$(document).ready(function() {
$(".po").click(function(){
var po = $(this).text();
var dataString = 'po='+ po;
$.ajax
({
type: "GET",
url: "projectitems.php",
data: dataString,
cache: false,
success: function(html)
{
$(this).closest(".resultsItems").html(html);
}
});
});
});
线路$(this).closest(".resultsItems").html(html);
(这个)到底指的是什么?我试图将返回的 ajax 结果附加到 <td>
称为 .resultsItems 但仅限于最初单击的选择器下方的那个?这可能吗?
为了明确起见,我不是在问 (this) 在 jQuery 中意味着什么,我是在问 (this) 在上面的代码中指的是什么!
最佳答案
this
指的是 $.ajax()
设置对象。要获得您想要的内容,您需要使用 context
选项来维护 this
,如下所示:
$.ajax({
context: this,
type: "GET",
url: "projectitems.php",
data: dataString,
cache: false,
success: function(html) {
$(this).closest(".resultsItems").html(html);
}
});
关于jquery - 这段特定代码片段中的 jQuery $(this) 指的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4379177/