【问题标题】:bootstrap open tab from a different page link从不同的页面链接引导打开选项卡
【发布时间】:2019-04-16 08:51:30
【问题描述】:

我有一个页面,上面有引导选项卡。我正在尝试从不同的页面打开特定的选项卡。我试图像书签示例http://localhost/view-customer#enquiries 等那样链接。但它不起作用。正在从查询中调用链接。查询脚本如下:

$(document).ready(function($){
$("#customers").autocomplete({
 source: "fetch_customers.php?cc=<?php echo $agencyid; ?>",
 minLength: 2,
 select: function(event, ui) {
var code = ui.item.id;
if(code != '#') {
location.href = '/view-customer/' + code + '#enquiries';
         }
 },
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
 }
});
});

我们可以看到location.href链接到http://localhost/view-customer/a1224#enquiries

查看客户页面如下所示。

 <div id="enquiries" name="enquiries" class="tab-pane fade in rowCSS">

<div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">

            </div>
        </div>
        <div class="row" >
               @include('enquiries_table')
      </div>
    </div>
  </div>

这是一个简单的概念,但仍然是为什么它不打开标签。可能引导选项卡的工作方式与普通 html 不同。我不确定。谁能指导我。

【问题讨论】:

  • 或者我需要使用
  • 谁能帮帮我。猜猜需要在我的 location.href 中添加一个哈希。
  • 你已经完成了一半。现在,您的 URL 中的每个选项卡都有一个唯一的目标标识符,即 #enquiries。现在,在页面(有标签)上,读取 URL 以提取目标标识符,然后使用 jQuery 激活相应的标签。

标签: jquery twitter-bootstrap


【解决方案1】:

由于您已经有了标签目标标识符,请使用以下代码定位页面上的特定标签。

$(document).ready(function(){
  const url = location.href; // get the browser URL
  const regEx = /\#(.*)/g; // match string starting with a "#" character
  const matched = url.match(regEx); // returns ['#enquiries']

  if(matched.length){
    let target = matched[0];
    // click on the target tab
    $(target).click(); // $('#enquiries').click();
  }
});

【讨论】:

    猜你喜欢
    • 2018-05-07
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-05
    • 2019-07-03
    • 2013-02-28
    • 1970-01-01
    相关资源
    最近更新 更多