对页面元素中事件进行提取,保持 ,使用完成后再进行事件绑定

对页面元素中事件进行提取,保持 ,使用完成后再进行事件绑定 

//事件处理器added by zbw911@
function eventkeeper(ele, type) {
    this.handlers = [];
    this.ele = $(ele);
    this.init = function () {

        var events = this.ele.data("events");
        if (events == undefined) return;

        var ex = events[type];
        if (ex == undefined) return;
        if (ex.length != undefined)
            for (var i in ex) {
                var v = ex[i];
                if (v.handler != undefined && $.isFunction(v.handler))
                    this.handlers.push(v.handler);
            }
        this.ele.unbind(type);
    }
    this.init();
    this.ReBind = function () {
        for (var i in this.handlers) {
            this.ele.bind(type, this.handlers[i]);
        }
    }
}

使用

 var keep = new eventkeeper($("#province"), "change");
 // 在这里做一些操作 。。。。。。
                                    keep.ReBind();
原文地址:https://www.cnblogs.com/zbw911/p/2549982.html