[英]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.