如何返回$(this) [英] How to return $(this)
问题描述
我使用jQuery并为一些内部工作制作了一个插件,这些插件基本上为我们的内部API构建了URL。无论如何,我想返回$(this),我没有得到正确的东西,我得到一个createdocumentfragment错误?
I'm using jQuery and made a plugin for some in house work that basically builds URLs for our internal API. Anyways, I want to return $(this) and im not getting the right thing and im getting a createdocumentfragment error?
插件代码:
$.get(base_url,{
agenda_id:defaults.id,
action:defaults.action+defaults.type,
output:defaults.output
},function(html){
defaults.callback(html);
});
工作正常,但我想添加return obj像这样:
That works fine, but i want to add return obj like so:
$.get(base_url,{
agenda_id:defaults.id,
action:defaults.action+defaults.type,
output:defaults.output
},function(html){
defaults.callback(html);
return obj;
});
Obj被设置在我的插件的开始处,obj在整个插件中工作正常。它设置为 obj = $(this);
Obj is set at the start of my plugin and obj works fine throughout the plugin. It's set as obj=$(this);
在我使用插件的脚本中,我有:
In my script, which uses the plugin, I have:
$('#agenda-live-preview').agenda({action:'get',type:'agenda',id:window.location.href.split('/').pop(),callback:function(html){
$(this).empty().append($(html).html());
}});
然而,它不起作用并返回:
However, it doesn't work and returns:
Error: doc.createDocumentFragment is not a function
Source File: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js
Line: 4373
在控制台错误日志中。任何想法如何返回$(this)并运行回调?
In the console error logs. Any ideas how to return $(this) AND run the callback?
推荐答案
我(最终)在您的其他问题留下评论。 :o)我很肯定你需要在你的插件中做到这一点:
I (finally) left a comment in your other question. :o) I'm pretty sure you need to do this in your plugin:
defaults.callback.call(this,html);
而不是:
instead of:
defaults.callback(html);
这篇关于如何返回$(this)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!