крюк в JQuery для переключения - PullRequest
0 голосов
/ 04 августа 2011

Я создал страницу, содержащую следующий код.Там мне нужно предупредить сообщение.Но это не работает.ЗАЧЕМ ?

Код:

$(document).ready(function() {
     $.hook('toggle');
    $('#test').bind('onbeforetoggle', function(e){alert(e.type)});

    $('#btnHide').click(function() {
        $('#divTest').toggle();

    });

});

jsFiddle demo

1 Ответ

0 голосов
/ 04 августа 2011

надеюсь, что некоторые помогают

http://jsfiddle.net/TzCXC/

  (function($){
    $.hook = function (fns) {
        fns = typeof fns === 'string' ? 
            fns.split(' ') : 
            $.makeArray(fns)
        ;

        jQuery.each( fns, function (i, method) {
            var old = $.fn[ method ];

            if ( old && !old.__hookold ) {

                $.fn[ method ] = function () {
                    this.triggerHandler('onbefore'+method);
                    this.triggerHandler('on'+method);
                    var ret = old.apply(this, arguments);
                    this.triggerHandler('onafter'+method);
                    return ret;
                };

                $.fn[ method ].__hookold = old;

            }
        }); 

    };

    $.unhook = function (fns) {
        fns = typeof fns === 'string' ? 
            fns.split(' ') : 
            $.makeArray(fns)
        ;

        jQuery.each( $.makeArray(fns), function (i, method) {
            var cur = $.fn[ method ];

            if ( cur && cur.__hookold ) {               
                $.fn[ method ] = cur.__hookold;         
            }
        });

    };
})(jQuery);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...