Example of using callback function

一个新手
Release: 2017-09-06 13:56:01
Original
1805 people have browsed it

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);});
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!