在这个特定的代码片段中引用的jQuery $(this)是什么?

ben*_*e89 6 jquery

$(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);
                        }
                    });
            });         
        });
Run Code Online (Sandbox Code Playgroud)

这条线$(this).closest(".resultsItems").html(html);到底是什么意思?我试图将返回的ajax结果附加到一个<td>被调用的.resultsItems,但仅限于初始点击选择器下方的那个?这可能吗?

只是为了说清楚我不是在问这个(这个)在jQuery中意味着什么,我在问我上面的代码中指的是什么(这个)!

Nic*_*ver 9

this指的是$.ajax()设置对象.要获得您想要的,您需要this使用以下context选项进行维护:

$.ajax({
  context: this,
  type: "GET",
  url: "projectitems.php",
  data: dataString,
  cache: false,
  success: function(html) {
    $(this).closest(".resultsItems").html(html);
  }
});
Run Code Online (Sandbox Code Playgroud)

  • 呸,那个该死的橙色酒吧就像我收拾回答一样. (3认同)