我用这个脚本:
(function() {
var tabContainers = $('div.tabs > div');
tabContainers.hide().filter(':first').show();
$(window).bind('hashchange', function () {
var hash = window.location.hash || '#first';
tabContainers.hide();
tabContainers.filter(hash).show();
$('div.tabs ul.tabNavigation a').removeClass('selected');
$('a[href=' + hash +']').addClass('selected');
});
$(window).trigger("hashchange");
});
Run Code Online (Sandbox Code Playgroud)
这部分代码为我提供了所需的一切.要从外部页面打开选项卡,我使用"index.php#first"href,例如.它打开页面,其中包含打开确切选项卡的选项卡,但它会跳转到锚点,我需要从顶部显示页面.
有谁知道,如何防止此代码的锚点跳转?