jQuery UI 选项卡,单击不同选项卡时更新 url
问题描述:
我正在使用 jQuery UI 的选项卡:http://jqueryui.com/demos/tabs/
I'm using the tabs of jQuery UI: http://jqueryui.com/demos/tabs/
如何在用户点击不同标签时通过添加锚链接来更新浏览器的当前网址:ex: url.html#tab-4 并同时推送浏览器的当前历史记录.
How to update the current url of the browser when the user click on a different tab by adding the anchor link to it: ex: url.html#tab-4 and pushing the current history of the browser at the same time.
谢谢!
答
这应该得到你想要的(使用 jQuery UI 1.8,在 1.9 及更高版本中使用 激活事件,请参阅代码示例的其他答案).我在 jQuery UI 演示中使用了示例 HTML;
This should get what you want (using jQuery UI 1.8, in version 1.9 and later use the activate event, see other answers for code example). I used the sample HTML in jQuery UI demos;
$( "#tabs" ).tabs({
select: function(event, ui) {
window.location.hash = ui.tab.hash;
}
});