插件扩展的几种方法

<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>

猜你喜欢

转载自www.cnblogs.com/resist/p/9074798.html