我是靠谱客的博主 清新大树,这篇文章主要介绍JQuery插件的两种写法,现在分享给大家,希望可以做个参考。

第一种

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插件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(89)

评论列表共有 0 条评论

立即
投稿
返回
顶部