Jquery Toggle two function not work in 1.10.1

前端 未结 7 1985
执念已碎
执念已碎 2020-12-17 03:04

Jquery Toggle two function not work in jquery 1.10.1 but work\'s on Jquery 1.8.3

HTML

For example, consider the HTML:

7条回答
  •  北海茫月
    2020-12-17 03:25

    DEMO

    DEMO jQuery 2.x (edge)

    use this clickToggle plugin as toggle function is removed from version 1.9

    (function ($) {
        $.fn.clickToggle = function (func1, func2) {
            var funcs = [func1, func2];
            this.data('toggleclicked', 0);
            this.click(function () {
                var data = $(this).data();
                var tc = data.toggleclicked;
                $.proxy(funcs[tc], this)();
                data.toggleclicked = (tc + 1) % 2;
            });
            return this;
        };
    }(jQuery));
    $('#target').clickToggle(function () {
        alert('First handler for .toggle() called.');
    }, function () {
        alert('Second handler for .toggle() called.');
    });
    

提交回复
热议问题