简体   繁体   English

我如何在jQuery插件代码中执行回调

[英]How do i execute a callback in a jQuery Plugin code

This may sound really like a newbie .. But i used the jQuery Boilerplate on this page - http://stefangabos.ro/jquery/jquery-plugin-boilerplate-revisited/ and created a plugin. 这听起来真的像是一个新手..但是我在此页面上使用了jQuery Boilerplate- http: //stefangabos.ro/jquery/jquery-plugin-boilerplate-revisited/并创建了一个插件。 Everything works fine, except now i want to add a callback. 一切正常,除非现在我想添加一个回调。 I want to execute this - 我要执行此-

$.Alerter({'message':'this is a test','onSuccess':function(data) { alert(data); } });

The onSuccess is a callback function which is added to the defaults. onSuccess是一个回调函数,已添加到默认值中。

My question is – how do i send the output to the onSuccess. 我的问题是–我如何将输出发送到onSuccess。 I want it to return back a TRUE or FALSE value after certain steps have been executed in the init() 我希望它在init()中执行某些步骤后返回TRUE或FALSE值

Something like this: 像这样:

plugin.result = null;

plugin.init = function() {
    // do stuff
    ...
    // save _result in public variable result 
    plugin.result = _result;
}

If you are writing this plugin for dom operations, you could also use it like plugin.data('result',_result); 如果您正在为dom操作编写此插件,则也可以像plugin.data('result',_result);一样使用它plugin.data('result',_result);

Since I don't know anything else I can't give further insight. 由于我什么都不知道,因此我无法提供进一步的见解。
Hope this will help you. 希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM