0

在我的 function.js 文件中,我有两个函数:第一个函数使用 ajax 加载我的页面。另一个是用于在我的主页上缩小标签内容。最初,这两个功能都有效。但是,当我单击任一菜单栏链接,然后单击主页链接返回主页时,我的选项卡区域不再起作用。我有一种感觉,organictabs() 函数只有在 index.html 首次加载时才会被调用。如何更改此设置,以便在每次加载新页面时调用 organictabs()?

// remap jQuery to $
(function($){})(window.jQuery);


/* trigger when page is ready */
$(document).ready(function (){
    initialize();

});

function initialize() {
    //Click on nav to load external content through AJAX
    $('#topnav a, #bottomnav a').not('#bottomnav #fbcallus a').click(function(e){

        e.preventDefault();

        $('#pages').load( e.target.href + ' #loadcontent'); //pages finished loading
    }); //clicked on nav
    //handle AJAX for left nav
$(function() {
        $("#tabedarea").organicTabs();
    });


}



    //Click on nav to load external content through AJAX
    // $('#topnav a').click(function(e){
    //  e.preventDefault();
    //  $('#pages').load( e.target.href + ' #loadcontent'); //pages finished loading
    // }); //clicked on nav



(function($) {

    $.organicTabs = function(el, options) {

        var base = this;
        base.$el = $(el);
        base.$navtabs = base.$el.find(".navtabs");

        base.init = function() {

            base.options = $.extend({},$.organicTabs.defaultOptions, options);

            // Accessible hiding fix
            $(".hidetabs").css({
                "position": "relative",
                "top": 0,
                "left": 0,
                "display": "none"
            }); 

            base.$navtabs.delegate("li > a", "click", function() {

                // Figure out current list via CSS class
                var curList = base.$el.find("a.current").attr("href").substring(1),

                // List moving to
                    $newList = $(this),

                // Figure out ID of new list
                    listID = $newList.attr("href").substring(1),

                // Set outer wrapper height to (static) height of current inner list
                    $allListWrap = base.$el.find(".list-wrap"),
                    curListHeight = $allListWrap.height();
                $allListWrap.height(curListHeight);

                if ((listID != curList) && ( base.$el.find(":animated").length == 0)) {

                    // Fade out current list
                    base.$el.find("#"+curList).fadeOut(base.options.speed, function() {

                        // Fade in new list on callback
                        base.$el.find("#"+listID).fadeIn(base.options.speed);

                        // Adjust outer wrapper to fit new list snuggly
                        //var newHeight = base.$el.find("#"+listID).height();
                        //$allListWrap.animate({
                        //    height: newHeight
                        //});

                        // Remove highlighting - Add to just-clicked tab
                        base.$el.find(".navtabs li a").removeClass("current");
                        $newList.addClass("current");

                    });

                }   

                // Don't behave like a regular link
                // Stop propegation and bubbling
                return false;
            });

        };
        base.init();
    };

    $.organicTabs.defaultOptions = {
        "speed": 300
    };

    $.fn.organicTabs = function(options) {
        return this.each(function() {
            (new $.organicTabs(this, options));
        });
    };

})(jQuery);
4

1 回答 1

1

我相信在 jquery 加载上使用完整的功能将解决您的问题:

function initialize() {
//Click on nav to load external content through AJAX
$('#topnav a, #bottomnav a').not('#bottomnav #fbcallus a').click(function(e){

    e.preventDefault();

    $('#pages').load( e.target.href + ' #loadcontent', function() { $("#tabedarea").organicTabs(); }); //pages finished loading
});
}
于 2012-04-16T13:23:21.367 回答