0

このスクリプトを調整しようとしています。画像をクリックすると他のdivが表示され、もう一方をクリックするとその情報が表示され、両方は表示されません。

(function ($) {
    $.fn.showHide = function (options) {
        //default vars for the plugin
        var defaults = {
            speed: 1000,
            easing: '',
            changeText: 0,
            showText: 'Show',
            hideText: 'Hide'
        };
        var options = $.extend(defaults, options);
        $(this).click(function () {
            $('.toggleDiv').slideUp(options.speed, options.easing);
            // this var stores which button you've clicked
            var toggleClick = $(this);
            // this reads the rel attribute of the button to determine which div id to toggle
            var toggleDiv = $(this).attr('rel');
            // here we toggle show/hide the correct div at the right speed and using which easing effect
            $(toggleDiv).slideToggle(options.speed, options.easing, function () {
                // this only fires once the animation is completed
                if (options.changeText == 1) {
                    $(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
                }
            });
            return false;
        });
    };
})(jQuery);

お知らせ下さい。http://papermashup.com/simple-jquery-showhide-div/に感謝します

4

1 に答える 1

0

jQuery のトグル イベント ハンドラーを見てみましょう。これにより、2 つの関数を要素にバインドし、交互のクリックでそれらを実行できます。そうすれば、どのクリックをクリックしたか、表示されているかどうかなどを追跡する必要がなくなります。

click簡単に言うと、ハンドラーをハンドラーに置き換えると、次のtoggle2 つの機能が得られます。

    $(this).toggle(function () {
        //what to do when your element is in its initial state
    }, function() {
        //what to do when your element is in its "clicked once" state
    }
于 2012-06-18T15:06:44.633 に答える