在IE7中轻松下载Jquery

时间:2012-09-14 13:56:54

标签: jquery internet-explorer-7

我正在使用这里发现的这个精彩的jquery插件...

http://appgrinders.github.com/jquery-easy-drop-down/

唯一的问题是,它在IE7中不起作用。我已经读过,有时会在IE7中使用小的语法差异。 Visual Studio给我一个语法错误,我在下面提到过。这可能是让IE7不高兴的原因吗?不是Jquery大师,我希望有人可以帮助我...

/* Cache a combined list of all dropdown elements, so each doc click isn't a DOM search */
(function( $ ){
var $dropdowns = $([]);
// Create a document click handler that will close any open dropdowns:
$(document).click(function(e) {$dropdowns.find('.dropdown-panel:visible').hide();});

var methods = {

    init : function( options ) { 

        // Add this set to our combined cache:
        $dropdowns = $dropdowns.add(this);

        // Create some defaults, extending them with any options that were provided
        var settings = $.extend( {}, options);

        return this.each(function() {        

            // dropdown plugin code here
            var $this = $(this);

            if (settings.width) {
                $this.find('.dropdown-panel').css('min-width',settings.width);
                $this.find('.dropdown-panel').css('width',settings.width);
            }
            if (settings.maxHeight) {
                $this.find('.dropdown-panel').css('max-height',settings.maxHeight);
            }

            /* NOTE: 2 ways to get id:
            var id = this.id;
            var id = $this.attr('id');
            */

            // Only proceed with click-event handler if the plugin
            // has not already been initialized on this given element:
            if ( $this.data('initialized') )
                return;
            else
                $this.data('initialized', true);

            $this.click(function(e) {

                e.stopPropagation();
                $dropdowns.not(this).find('.dropdown-panel:visible').hide()
                var $target = $(e.target);

                // If the click is on the dropdown button, 
                if ($target.is('.dropdown-button, .dropdown-icon')) {
                    $(this).find('.dropdown-panel').slideToggle('fast');
                }
                // Else, if it's in the panel, do the callback.
                else {
                    if (settings.callback) {
                        callback = settings.callback;
                        callback($target);
                    }
                }
            });

        });

    },
    show : function( ) {

        return this.each(function() {
            $(this).find('.dropdown-panel:hidden').slideDown('fast');
        });
    },
    hide : function( ) { 

        return this.each(function() {
            $(this).find('.dropdown-panel:visible').slideUp('fast');
        }); 
    },
    toggle : function( ) { 

        return this.each(function() {
            $(this).find('.dropdown-panel').slideToggle('fast');
        }); 
    },

};//VS 2010 gives me 'Expected identifier or string' on this line where the curly brace is

$.fn.dropdown = function( method ) {

    // Method calling logic
    if ( methods[method] ) {
        return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
        return methods.init.apply( this, arguments );
    } else {
        $.error( 'Method ' +  method + ' does not exist on jQuery.dropdown' );
    }

};})( jQuery );

1 个答案:

答案 0 :(得分:0)

我明白了。

上面的行中有一个流氓逗号,我提到VS给了我一个错误。 DOH!

我删除了,现在IE7很开心!