jQuery自定义插件

来源:互联网 发布:声音频率测试软件手机 编辑:程序博客网 时间:2024/06/06 10:44

jQuery自定义插件

jQuery.prototype.sayHello = function(){   console.log("hello");}$(document).sayHello();//相当于$.fn.sayHello = function(){    console.log("hello");}

直接给原对象增加一个方法,那么所有的对象都可以使用这个方法

例子:
新建一个bgColor的方法

$(function(){  $.fn.bgColor = function(color){    this.css("backgroundColor",color);  };    $("div").bgColor("red");});
原创粉丝点击