从另一个页面链接到 Bootstrap 3 手风琴内的 DIV

Linking to a DIV inside a Bootstrap 3 accordion from another page

我看到了一个类似问题的绝妙解决方案 over here, but for some reason I can't seem to get the same solution to work on my page. I'm trying to create a direct link to the section, but when I type in http://www.scicoll.org/events.html#DC-GRB 它似乎不起作用。

我是 JavaScript 的新手(总有一天我会通过剪切和粘贴!),所以任何帮助将不胜感激!

实际上你有一个正常工作的:

$(document).ready(function () {
  location.hash && $(location.hash + '.collapse').collapse('show');
});

显示所需信息的折叠现在不是您的问题。 当您的 URL 散列 来自不同的选项卡 时,您只需要捕获并在隐藏时显示它。您可以在页面底部的 jquery 脚本中添加此代码:

$(document).ready(function () {
  location.hash && $(location.hash + '.collapse').collapse('show');
  if(location.hash.length > 2 && location.hash.substring(1,3) == "DC"){
    $('[href=#past]').trigger('click');
  }
});

这意味着:如果您的 location.hash 已启用且大于 2 (f.e。#DC-GRB),您将在相关的 [=16] 上触发事件 "click" =]link里面有你的信息。

或者(你可以把逻辑验证放在前面):

if(location.hash){
    $("a[href=#"+$(location.hash).closest(".tab-pane").attr("id")+"]").trigger("click");
}

在哈希和选项卡之间添加所有验证流程。