JQuery 拓展方法

        // 拓展jq的方法
        jQuery.fn.alertText = function (val) { // jQuery.fn==jQuery.prototype
            alert("this is new function" + val);
        }
        //以上写法等价于:  jQuery.fn.extend({ abc: function () { alert(111) } });
         jQuery.extend({
            alertText2: function (val) {
                alert("this is new function " + val);
            }
        });
        var a; // 也可以是$("#id")
        $(a).alertText("wjaaa");
        $.alertText2("wjbbbb");


你可能感兴趣的:(JQuery 拓展方法)