I've been trying to find a way to change the window.location.hash to the currently selected tab in Jquery UI Tabs.
I've tried:
$("#tabs > ul").tabs();
$("#tabs > ul").bind("tabsshow", function(event, ui) {
window.location.hash = ui.tab;
})
This results in changing the hash to #undefined when the tab is changed.
I've also tried:
$("#tabs > ul").tabs({
select: function(event, ui) {
window.location.hash = ui.tab }
});
But this doesn't seem to be triggered at all.
Any help would be appreciated. Thanks.
Edit: It looks like part of my initial problem had something to do with js somewhere else interfering with this. Both the accepted answer and the other suggested answer slightly modified do work. Thanks all.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…