第一种
js:
(function (jQuery){
this.show =function(title){
this.title=title;
};
this.show2 =function(){
alert(this.title);
};
jQuery.messager =this;
return jQuery;
})(jQuery);
html:
<script src="jquery.js"></script>
<script src="js.js"></script>
<script>
$(document).ready(function(){
$.messager.show("this is a test");
$.messager.show2();
});
</script>
第二种
js:
$.fn.messager =function(options){
var defaults = {
title:"this is a test!"
};
$.extend(defaults,options);
alert(defaults.title);
return this;
};
html:
<script src="jquery.js"></script>
<script src="js.js"></script>
<script>
$(document).ready(function(){
$("#d").messager().hide();
});
</script>
最后
以上就是清新大树最近收集整理的关于JQuery插件的两种写法的全部内容,更多相关JQuery插件内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复