jQuery.fn.extend 与 jQuery.extend 用法

jquery 本身并不提供 jQuery.color() 这个方法,如果我们需要对jQuery本身提供的方法进行扩展,则我们就需要是用jQuery.fn.extend:
jQuery.fn.extend({
    color:function(val)
    {
          if(val==undefined){
         
               return $(this).css("color");
            }else{
    
              return $(this).css("color",val);
            }
    }
})
$(this).color("red");//对jquery对象进行颜色设置
alert($(this).color());//获取jquery对象的颜色,并用对话框弹出
2.jQuery.extend  对jQuery对象的扩展,可以理解为静态方法,不需要实例jQuery就可以使用

  jQuery.extend( {
    add:function(a,b)//myShow
    {
     return a+b;
    }
  })



调用:alert($.add(3, 4));

你可能感兴趣的:(jquery,css)