2012-04-02 64 views
0

我對JavaScript和jQuery相對來說比較新。jQuery燒烤插件混亂

我正在使用jQuery BBQ插件提供後臺頁面功能。我有以下實現:

// Be sure to bind to the "hashchange" event on document.ready, not 
// before, or else it may fail in IE6/7. This limitation may be 
// removed in a future revision. 
$(function(){ 

    // Override the default behavior of all `a` elements so that, when 
    // clicked, their `href` value is pushed onto the history hash 
    // instead of being navigated to directly. 
    $(".content a").click(function(){ 
    var href = $(this).attr("href"); 

    // Push this URL "state" onto the history hash. 
    $.bbq.pushState({ url: href }); 

    // Prevent the default click behavior. 
    return false; 
    }); 

    // Bind a callback that executes when document.location.hash changes. 
    $(window).bind("hashchange", function(e) { 
    // In jQuery 1.4, use e.getState("url"); 
    var url = $.bbq.getState("url"); 

    // In this example, whenever the event is triggered, iterate over 
    // all `a` elements, setting the class to "current" if the 
    // href matches (and removing it otherwise). 
    $("a").each(function(){ 
     var href = $(this).attr("href"); 

     if (href === url) { 
     $(this).addClass("current"); 
     } else { 
     $(this).removeClass("current"); 
     } 
    }); 

    console.log(url) 
    $.getScript(url) 

    }); 

    // Since the event is only triggered when the hash changes, we need 
    // to trigger the event now, to handle the hash the page may have 
    // loaded with. 
    $(window).trigger("hashchange"); 
}); 

現在這個偉大的工程,如果我直接去找mysite.com/brands網址加載罰款,當我點擊選項卡中的URL顯示了這樣http://localhost:3000/trends#url=/trends/latest這是確定的,當我瀏覽頁面上的其他選項卡時,後退按鈕將起作用。

$ .getScript調用當前將我的部分加載到模板中的JavaScript。

問題是,它似乎只能在單層基礎上工作。如果我點擊我的父導航項趨勢,然後點擊一個標籤,插件不起作用。它像它拒絕看到它。

我可以看到燒烤插件具有高級功能,但我不知道我想要的是甚至是先進的。

任何人都可以提出從jQuery,或以前的經驗與插件我可以做什麼?

非常感謝。

感謝,

傑夫

回答