Вот еще один способ решить проблему.
Сначала добавьте строку к событию клика, чтобы отобразить хеш в адресной строке:
$('#myTab').on('click', 'a', function (e) {
e.preventDefault();
// Add this line
window.location.hash = $(this).attr('href');
$(this).tab('show');
})
Затем убедитесь, что правая вкладка активирована onload
, добавив эту часть в вызов готовности документа.
if(window.location.hash){
$('#myTab').find('a[href="'+window.location.hash+'"]').tab('show');
}
Все вместе можно написать так:
// Cache the ID
var navbox = $('#myTab');
// Activate tab on click
navbox.on('click', 'a', function (e) {
var $this = $(this);
// Prevent the ***default*** behavior
e.preventDefault();
// Set the hash to the address bar
window.location.hash = $this.attr('href');
// Activate the clicked tab
$this.tab('show');
})
// If we have a hash in the address bar
if(window.location.hash){
// Show right tab on load (read hash from address bar)
navbox.find('a[href="'+window.location.hash+'"]').tab('show');
}
person
HaNdTriX
schedule
20.08.2012