How to define a global JQuery plugin?

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

Question: How jquery custom plug-ins to use?

First of all:

          Introducing jquery basic packet jquery.js

Since the format defined widget:
     $ .extend ({method name. 1: function () {
      },
      the method name 2: function () {
      }})

Code demonstrates:

html:

<input id="btn1-check" type="button" value="插件方式--点击选中复选框" onclick="checkFn1()">
    <input id="btn2-uncheck" type="button" value="插件方式--点击取消复选框选中" onclick="uncheckFn2()">

js:

         //自定义:$.fn.extend这里也可以把fn省略
        $.fn.extend({
            check:function(){
                $(":checkbox").prop("checked",true);
            },
            uncheck:function(){
                $(":checkbox").prop("checked",false);
            }
        });

        //引用插件
        function checkFn1() {
            $("#btn1-check").check();
        }
        function uncheckFn2() {
            $("#btn2-uncheck").uncheck();
        }


 

Guess you like

Origin blog.csdn.net/longyanchen/article/details/93380068