jQuery开发插件模板

来源:互联网 发布:手机如何共享wifi网络 编辑:程序博客网 时间:2024/06/06 09:33

使用jQuery开发一个小插件的模板写法:
HTML代码:

<span id="test">test</span>

JS代码:

<script type="text/javascript">!function ($) {     "use strict";      var Plugins =function(element,option){            this.$element =element;            this.defaults = {                "color":"green",                "fontSize":"16px",                "fontWeight":"bold"            }            this.options = $.extend({}, this.defaults, option)     }    Plugins.prototype = {        changecss:function(){            return this.$element.css({                'color':this.options.color,                'fontSize':this.options.fontSize,                "fontWeight":this.options.fontWeight            })        }    }    $.fn.changeCss = function(options){        var myPlugins = new Plugins(this,options);        return myPlugins.changecss();    }}(window.jQuery);</script>

调用方式:

$("#aaa").changeCss ({                        "color":"yellow",                        "fontSize":"20px",                        "fontWeight":"bold"                    })
0 0
原创粉丝点击