1
$.ajax({url: path_to_file, cache: false, success: function(html_result){
    $("#window_" + this.id + "_cont_buffer").html(html_result);})

接着。这个函数调用在一个类的函数中。this.id是所述类的属性。这会将 this.id 的函数值传递给匿名函数的字符串,还是会在函数实际被调用时尝试评估它,因此没有意义。

如果这不能按我的意愿工作,您能否推荐我如何实现这一目标。

4

2 回答 2

2

在特定情况下$.ajax()this可以使用context属性指定。因此,Matthew 的解决方案为您提供了this在您进行$.ajax函数调用的函数中指定的内容。

您可以查看jQuery 文档以获取有关设置回调this的更多信息。success

于 2010-04-29T13:54:23.220 回答
1

默认情况下this将是一个内部 jQuery 对象。但是,您可以通过显式指定context: this作为调用的一部分来覆盖它。然后,this将是您从中调用它的对象。

$.ajax({url: path_to_file, context: this, cache: false, success: function(html_result){
    $("#window_" + this.id + "_cont_buffer").html(html_result);})

会做你想做的。

于 2010-04-29T13:50:48.310 回答