【问题标题】:Move from to a specific tab in another page从另一个页面中的特定选项卡移动
【发布时间】:2017-11-10 15:35:53
【问题描述】:

我有这个代码:

<ul id="tabsss">
    <li  class="underUl"> <a href="about.php#History"> - History</a></li>
    <li  class="underUl"><a href="about.php#Concept"> - The Concept</a></li>
    <li  id="cst1" class="underUl"><a href="about.php#Choose_CST"> - Why Choose CST?</a></li>
    <li  id="management1" class="underUl">- Management</li>
    <li   id="department1" class="underUl">- Department</li>
</ul>

在另一个页面我有这些&lt;div&gt;

<div class="tab-pane active"  id="History">test</div>
<div class="tab-pane"  id="Concept">test1</div>
<div class="tab-pane" id="Choose_CST">ssss</div>
<div class="tab-pane" id="Management">ssss</div>
<div class="tab-pane" id="Department">ssss</div>

我想转到其他页面中的特定选项卡。现在只打开第一个。

有什么帮助吗?提前致谢。

【问题讨论】:

  • 如果我理解正确,您想在初始页面加载时滚动到特定元素?
  • 不,我需要转到其他页面中的特定元素.. @DavidePerozzi
  • 那么你的tab-pane元素是放在about.php页面上的吗?如果是这样,哈希后缀应该可以解决问题。因此“about.php#History”将滚动到 id 为“History”的元素。确保元素正确呈现并且可见,并且 id 不会出现多次。

标签: javascript jquery tabs bootstrap-tabs


【解决方案1】:

您需要在加载第二页时添加一些 javascript。

类似:

if (window.location.hash == "History"){
   $('.tab').hide(); //hide all other tabs
   $('#History').show();
}

如果您在 about 页面上有标签,可以这样完成:

var currentTab = window.location.hash;
$('a[href="#'+currentTab+'"]').tab('show');

【讨论】:

    【解决方案2】:

    又看了一遍你的问题,用 JavaScript 很容易实现:

    $(document).ready(function(){    
      url_params = window.location.hash;  
      tabParams = $('a[href="' + url_params + '"]');
      console.log(tabParams);
      console.log(url_params);
      if (tabParams.length === 0) 
      {
      //Activate first tab
      //Show first tab content
      } 
      else 
      {
        tabParams.click();
      }    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多