美文网首页
自定义插件

自定义插件

作者: 琪33 | 来源:发表于2018-04-30 11:15 被阅读0次
<script src="jquery-1.11.1.js"></script>
    <script src="jquery-MrLv-1.11.1-min.js"></script>
    <script>
        $(function () {
            //调用插件中的方法
            //第一种制作方法
//            $("button").on("click", function () {
//                $("button").setColorRed();
//            })


            //第二种绑定方法
            $("button").on("click", function () {
                $.setColorRed($(this));
            })

        })
    </script>
</head>
<body>
<button>按钮1</button>
<button>按钮2</button>
<button>按钮3</button>
<button>按钮4</button>
<button>按钮5</button>
<button>按钮6</button>
</body>
/**
 * Created by Lenovo on 2016/9/17.
 */

//绑定到原型上,调用者是jquery对象
$.fn.setColorRed = function () {
    this.css({"color":"red"});
}


//绑定到$上,调用者是$
$.setColorRed = function (e) {
    e.css({"color":"red"});
}

相关文章

网友评论

      本文标题:自定义插件

      本文链接:https://www.haomeiwen.com/subject/saezlftx.html