【发布时间】:2011-10-21 23:05:31
【问题描述】:
我正在关注this documentation 并使用它来下载数据并将其应用到 DOM。但是,我似乎无法应用它:
this.html 不是函数:this.html(ajax_load);
代码:
(function( $ ){
$.fn.tasks = function() {
// there's no need to do $(this) because
// "this" is already a jquery object
// $(this) would be the same as $($('#element'));
$.ajax({
url: "include/tasks_handler.php?action=gettasks&list=default",
beforeSend: function() {
this.html(ajax_load);
},
success: function(html){
this.html(html);
}
});
};
})( jQuery );
$("#taskList").tasks();
我也尝试过 $(this),它可以阻止它破坏,但它不会将内容注入选择器。
想法?
【问题讨论】:
-
使用
$(this)使其成为具有.html方法的jQuery 对象。发布 then 发生的事情作为问题(因为那是实际问题:) -
@FLX:你想用
this指代什么? -
另外,
this在 beforeSend 的回调范围内不可用。您必须执行var somevar = this;才能使其在回调中可见——有趣的this范围规则。
标签: jquery-plugins jquery jquery-selectors