Warning: Illegal string offset 'html' in /data/www/community.itbbs.cn/htdocs/cache/skin_cache/cacheid_1/skin_topic.php on line 909

Warning: Cannot modify header information - headers already sent by (output started at /data/www/community.itbbs.cn/htdocs/cache/skin_cache/cacheid_1/skin_topic.php:909) in /data/www/community.itbbs.cn/htdocs/admin/sources/classes/output/formats/html/htmlOutput.php on line 114

Warning: Cannot modify header information - headers already sent by (output started at /data/www/community.itbbs.cn/htdocs/cache/skin_cache/cacheid_1/skin_topic.php:909) in /data/www/community.itbbs.cn/htdocs/admin/sources/classes/output/formats/html/htmlOutput.php on line 127

Warning: Cannot modify header information - headers already sent by (output started at /data/www/community.itbbs.cn/htdocs/cache/skin_cache/cacheid_1/skin_topic.php:909) in /data/www/community.itbbs.cn/htdocs/admin/sources/classes/output/formats/html/htmlOutput.php on line 136

Warning: Cannot modify header information - headers already sent by (output started at /data/www/community.itbbs.cn/htdocs/cache/skin_cache/cacheid_1/skin_topic.php:909) in /data/www/community.itbbs.cn/htdocs/admin/sources/classes/output/formats/html/htmlOutput.php on line 137

Warning: Cannot modify header information - headers already sent by (output started at /data/www/community.itbbs.cn/htdocs/cache/skin_cache/cacheid_1/skin_topic.php:909) in /data/www/community.itbbs.cn/htdocs/admin/sources/classes/output/formats/html/htmlOutput.php on line 141
创建 jQuery 插件的简单示例 - IT技术论坛

Jump to content


创建 jQuery 插件的简单示例


  • You cannot reply to this topic
No replies to this topic

#1 冰力

    Administrator

  • 总版主
  • 1318 posts

Posted 2011/01/24 10:58:09

插件代码
(function($){ 
    $.fn.extend({ 
        myFunk: function() { 
            // 此处必须返回jQuery对象
            return $(); 
        }, 
        myPunk: function() { 
            return this.addClass('punked') 
                      .bind('click', function(){ 
                alert('You were punked!'); 
            }); 
        } 
    }); 
})(jQuery);

使用方法
$('.select').myFunk(); 
$('.select').myPunk();