2012-02-26 71 views
0

我在jQuery的工具以下标签:如何根据选项卡的名称在ajaxed选项卡中创建jQuery工具的历史记录?

<!-- tabs --> 
<ul class="css-tabs"> 
    <li><a href="/example/a">ABC</a></li> 
    <li><a href="/example/b">DEF</a></li> 
</ul> 

<!-- single pane. it is always visible --> 
<div class="css-panes"> 
    <div style="display:block"></div> 
</div> 

而且我的历史开启。

所以,当我按下第一个选项卡上ABC,我的网址: www.example.com/example/a#/example/a

而当第二个标签DEF被点击的URL看起来是这样的: www.example.com/example/b#/example/b

我不喜欢url的外观如何,如果标签历史记录是根据标签的名称(ABCDEF):www.example.com/example/a#ABCwww.example.com/example/b#DEF

我一直在寻找这个相当长的一段时间,但找不到任何关于如何可以做到这一点什么...

回答

2

好了,我要回答我的问题> _ <

无我没有地方在网络上找到了解决办法,我解决我自己......

的解决方案是jQuery的工具版本1.2.6 稳定

jQuery的工具代码,涉及历史工具,你可以从这里改变它:

(function(a){var b,c,d,e;a.tools=a.tools||{version:"v1.2.6"},a.tools.history={init:function(g){e||(a.browser.msie&&a.browser.version<"8"?c||(c=a("<iframe/>").attr("src","javascript:false;").hide().get(0),a("body").prepend(c),setInterval(function(){var d=c.contentWindow.document,e=d.location.hash;b!==e&&a(window).trigger("hash",e)},100),f(location.hash||"#")):setInterval(function(){var c=location.hash;c!==b&&a(window).trigger("hash",c)},100),d=d?d.add(g):g,g.click(function(b){var d=a(this).attr("href");c&&f(d);if(d.slice(0,1)!="#"){location.href="#"+d;return b.preventDefault()}}),e=!0)}};function f(a){if(a){var b=c.contentWindow.document;b.open().close(),b.location.hash=a}}a(window).bind("hash",function(c,e){e?d.filter(function(){var b=a(this).attr("href");return b==e||b==e.replace("#","")}).trigger("history",[e]):d.eq(0).trigger("history",[e]),b=e}),a.fn.history=function(b){a.tools.history.init(this);return this.bind("history",b)}})(jQuery); 

更改为:(不需要新的线路,你可以删除它们,并返回到一个行)

(function(a) 
{ 
    var b,c,d,e;a.tools=a.tools||{version:"v1.2.6"},a.tools.history={init:function(g){e||(a.browser.msie&&a.browser.version<"8"?c||(c=a("<iframe/>").attr("src","javascript:false;").hide().get(0), 
    a("body").prepend(c),setInterval(function(){var d=c.contentWindow.document,e=d.location.hash;b!==e&&a(window).trigger("hash",e)},100), 
    f(location.hash||"#")):setInterval(function(){var c=location.hash;c!==b&&a(window).trigger("hash",c)},100),d=d?d.add(g):g, 
    g.click(function(b){var d=a(this).attr("href"); 
    c&&f(d);if(d.slice(0,1)!="#"){location.href="#"+a(this).attr("name");return b.preventDefault()}}),e=!0)}}; 

    function f(a) 
    { 
    if(a) 
    { 
     var b=c.contentWindow.document; 
     b.open().close(), 
     b.location.hash=a 
    } 
    }a(window).bind("hash",function(c,e){e?d.filter(function(){var b=a(this).attr("name");return b==e||b==e.replace("#","")}).trigger("history",[e]):d.eq(0).trigger("history",[e]),b=e}), 
    a.fn.history=function(b){a.tools.history.init(this);return this.bind("history",b)} 
} 
) 

的变化是两个简单的变化: 此:

location.href="#"+d 

改成这样:

location.href="#"+a(this).attr("name") 

这:

var b=a(this).attr("href"); 

改成这样:

var b=a(this).attr("name"); 

还多了一个重要的事情,你需要将“NAME”属性添加到您的标签,并把你希望出现在后的地址名称#(在我来说,我希望出现在选项卡的同一路段/名),就像这样:

<!-- tabs --> 
<ul class="css-tabs"> 
    <li><a href="/example/a" name="ABC">ABC</a></li> 
    <li><a href="/example/b" name="DEF">DEF</a></li> 
</ul> 

<!-- single pane. it is always visible --> 
<div class="css-panes"> 
    <div style="display:block"></div> 
</div> 

就是这样,你现在有一个工作jQuery的工具选项卡的历史与“#NAME工作的选项卡“而不是”#href林K”:d 像这些:

www.example.com/example/a#ABC

www.example。com/example/b#DEF

如果您不想使用“name”属性,而是使用id或class,那么请更改我将名称放入id或class的位置,但请确保将id或class放在您的选项卡中太...

相关问题