这个答案来自一个重复的问题:https://stackoverflow.com/a/20811416/3123649 https://stackoverflow.com/a/20811416/3123649.
您可以从链接的 url 中传递选项卡 div id 并使用它进行选择。
来自index.html的主页链接:
<a href="products.php?tabId=tile">tile</a>
<a href="products.php?tabId=metal">metal</a>
将此 javascript 添加到标签页
<script type="text/javascript">
// To get parameter from url
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
$.extend($.expr[':'], {
attrNameStart: function (el, i, props) {
var hasAttribute = false;
$.each(el.attributes, function (i, attr) {
if (attr.name.indexOf(props[3]) !== -1) {
hasAttribute = true;
return false;
}
});
return hasAttribute;
}
});
// deselect tabs and select the tab by id
function focusTab(id) {
$("#tile").hide().removeClass("active");
$("#metal").hide().removeClass("active");
$("#shingle").hide().removeClass("active");
$("#flat").hide().removeClass("active");
$("#custom").hide().removeClass("active");
var toggle = $(id).parent().find("div");
toggle.hide().removeClass("active");
$('a:attrNameStart(data-toggle)').removeClass("active");
var id1 = getParameterByName("tabId");
var toggler = $('*[data-toggle=' + id1 + ']');
$(toggler).addClass("active");
$(id).show().addClass("active");
}
$(function() {
$(".tabs a").html5jTabs();
// Get the tab id from the url
var tabId = "#" + getParameterByName("tabId");
// Focus the tab
focusTab(tabId);
});
</script>
编辑:替换原来的focusTab
具有编辑功能。还添加扩展功能attrNameStart
。这应该取消选择默认的活动选项卡。
编辑2:focusTab
有一个错误,现在应该可以工作了
** 我查看了您的网站,我的解决方案似乎对您有用。我注意到一件事。您初始化html5jTabs()
twice.
删除顶部的第一个调用
<script type="text/javascript">
$(function() {
$(".tabs a").html5jTabs();
});
</script>