开发者

.bind() statement not working in jQuery Easy Confirmation plugin

开发者 https://www.devze.com 2023-04-08 05:34 出处:网络
Did anyone who used jQuery Easy Confirmation plugin run into this issue - the button upon which the confirm box is bound loses its original click event after the first click? I had to change the plugi

Did anyone who used jQuery Easy Confirmation plugin run into this issue - the button upon which the confirm box is bound loses its original click event after the first click? I had to change the plugin code to this to make it work. The difference here is between .bind and .click. Can anyone explain why? Pls. let me know if my question is not clear. Thx!

开发者_如何转开发

Original plugin code:

     // Re-bind old events
            var rebindHandlers = function () {

                if (target._handlers != undefined) {
                    jQuery.each(target._handlers, function () {
                        //this is the difference
                        $target.bind(type, this);   
                    });
                }
            }

Changed (working) code:

    // Re-bind old events
            var rebindHandlers = function () {

                if (target._handlers != undefined) {
                    jQuery.each(target._handlers, function () {
                        //this is the difference
                        if(type == 'click')
                            $target.click(this);
                        else {
                            $target.bind(type, this);   
                        }
                    });
                }
            }


Try using some alerts to see what's happening...

// Re-bind old events 
var rebindHandlers = function () {
            if (target._handlers != undefined) {
                jQuery.each(target._handlers, function () {
                    if(type == 'click')
                        alert('$target.click(' + this + ');');
                        //$target.click(this);
                    else {
                        alert('$target.bind(' + type + ', ' + this + ');');
                        //$target.bind(type, this);   
                    }
                });
            }
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号