如何封装一个简易的jQuery插件?
- 内容介绍
- 文章标签
- 相关推荐
本文共计151个文字,预计阅读时间需要1分钟。
[gistfile1.txt] [求职必备] 开发一个简单的jQuery插件 - 选项卡
javascript(function($) { $.fn.tab=function(options) { var defaults={ activeClass: 'active', contentClass: 'tab-content', event: 'click', tabs: '.tab', contents: '.tab-content' }; var options=$.extend(defaults, options);
return this.each(function() { var $this=$(this), $tabs=$this.find(options.tabs), $contents=$this.find(options.contents);
$tabs.on(options.event, function() { var index=$(this).index(); $tabs.removeClass(options.activeClass); $(this).addClass(options.activeClass); $contents.hide(); $($contents[index]).show(); });
$tabs.first().addClass(options.activeClass); $($contents.first()).show(); }); };})(jQuery);
- 11
- 22
- 33
本文共计151个文字,预计阅读时间需要1分钟。
[gistfile1.txt] [求职必备] 开发一个简单的jQuery插件 - 选项卡
javascript(function($) { $.fn.tab=function(options) { var defaults={ activeClass: 'active', contentClass: 'tab-content', event: 'click', tabs: '.tab', contents: '.tab-content' }; var options=$.extend(defaults, options);
return this.each(function() { var $this=$(this), $tabs=$this.find(options.tabs), $contents=$this.find(options.contents);
$tabs.on(options.event, function() { var index=$(this).index(); $tabs.removeClass(options.activeClass); $(this).addClass(options.activeClass); $contents.hide(); $($contents[index]).show(); });
$tabs.first().addClass(options.activeClass); $($contents.first()).show(); }); };})(jQuery);
- 11
- 22
- 33

