jquery插件开发

index.html文件



  
    
    
    
    
    Bootstrap 101 Template

    
    

  
  
  
    

hello word

dddd

jqueryTest.js文件

;(function($){
/*  $.fn.extend({

    color: function(value){
      return this.css("color",value);
    }
    //如果用了 this.each(function() {
    //要用 $(this)
   

  });*/

$.fn.myPlugin = function(options) {
    var defaults = {
        'color': 'red',
        'fontSize': '12px'
    };
    var settings = $.extend({},defaults, options);//将一个空对象做为第一个参数
    return this.css({
        'color': settings.color,
        'fontSize': settings.fontSize
    });
}

})(jQuery);

Reference:

jQuery官网学习中心关于插件开发的文章: http://learn.jquery.com/plugins/
jQuery官网插件中心:http://plugins.jquery.com/
jQuery官网插件发布指南:http://plugins.jquery.com/docs/publish/
JavaScript Hoist :http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html
Google Web Developer Tool : https://developers.google.com/closure/

你可能感兴趣的:(jquery插件开发)