插件扩展的几种方法

<script>
//第一种:扩展Jquery原型对象的方法
(function($) {
$.fn.logText = function() {
console.log(this.text());
}
})(jQuery);
 
$(function() {
   //自定义的原型方法,也就是jquery插件
$(".text01").logText();
});

//第二种:扩展jquery构造函数上的插件(方法)
$.extend({
logTime: function() {
console.log(new Date());
}
});
var s = $.logTime();
</script>
posted @ 2018-05-22 23:36  吾将上下而求之  阅读(124)  评论(0编辑  收藏  举报