[英]jQuery BBQ Plugin Confusion
我對JavaScript和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可以很好地加載,並且當我單擊選項卡時,URL顯示如下:http:// localhost:3000 / trends#url = / trends / latest好的,當我瀏覽頁面上的其他選項卡時,后退按鈕將起作用。
$ .getScript調用當前將我的局部加載到模板中的JavaScript。
問題在於它似乎只能在一層基礎上工作。 如果單擊父級導航項“趨勢”,然后單擊一個選項卡,則該插件不起作用。 就像它拒絕看到它。
我可以看到BBQ插件具有高級功能,但是我不確定我想要的內容是否甚至高級。
任何人都可以從jQuery或以前的插件經驗中提出建議,我該怎么做?
非常感激。
謝謝,
傑夫
您可能想要“兩個菜單”中的“兩層” ... jquery-bbq網站上更高級的示例可能是您正在尋找的東西: http : //benalman.com/code/projects/jquery-bbq/示例/高級片段/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.