Excerpt:
Depending on how your plug-in is defined
$.fn.xtab = function(setting,callback)
xtab method should be able to receive two parameters: setting (configuration parameters) and callback (callback function).
So you should call it like this:
$(".element").xtab({}, function(){cosle.log('this is callback');});
If you want to use setting or other parameters and methods in the plug-in in the callback, you need to pass the parameters in when the callback is called:
$.fn.xtab = function(setting, callback){ var $this = $(this); // 将配置参数缓存在当前 jquery 对象上 $this.data('xtab-setting', setting); $this.data('xtab-callback', callback); // 假设点击时,调用 callback,并且传入配置参数 $this.click(function(){ callback($this.data('xtab-setting').value); }); }//调用: $('.p').xtab({value:'test'}, function(val){console.info(val);});
The above are just examples.
The above is the detailed content of Example of using callback function. For more information, please follow other related articles on the PHP Chinese website!