2015-06-23 39 views
2

即时通讯工作与引导3项目。 我想从“主页”链接到特定的打开选项卡。 我阅读并测试了这么多的机会,但没有任何工作。从外部链接打开活动标签

我最近在这里:

$activetabbuehne = (params.activeTab is null or params.activeTab == 'tab_a') ? 'class="active"' : ''; 
 
$activetabhoehe = (params.activeTab == 'tab_b') ? 'class="active"' : ''; 
 
$activetabaudio = (params.activeTab == 'tab_c') ? 'class="active"' : ''; 
 
$activetabstudio = (params.activeTab == 'tab_d') ? 'class="active"' : ''; 
 
$activetabsonder = (params.activeTab == 'tab_e') ? 'class="active"' : ''; 
 
$activetabinstall = (params.activeTab == 'tab_f') ? 'class="active"' : '';
<ul class="nav nav-pills nav-stacked col-xs-12 col-md-4"> 
 
    <li $activetabbuehne><a href="#tab_a" data-toggle="pill" style="font-weight:500;">BÜHNENBAU<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
 
    <li $activetabhoehe><a href="#tab_b" data-toggle="pill" style="font-weight:500;">HÖHENARBEITEN<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 26px;color: #db001b;">+</span></a></li> 
 
    <li $activetabaudio><a href="#tab_c" data-toggle="pill" style="font-weight:500;">AUDIO-, VIDEO-, LICHTTECHNIK<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
 
    <li $activetabstudio><a href="#tab_d" data-toggle="pill" style="font-weight:500;">STUDIO<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
 
    <li $activetabsonder><a href="#tab_e" data-toggle="pill" style="font-weight:500;">SONDERLÖSUNGEN<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
 
    <li $activetabinstall><a href="#tab_f" data-toggle="pill" style="font-weight:500;">INSTALLATIONEN<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
 
</ul>

这里是我使用的dev.page测试链接:

https://amphire.de/dev/leistungen/?activeTab=tab_a

感谢您的帮助。

+0

你混合的语言?它看起来像你试图在HTML中打印一个JS字符串,只需将它放在标记中即可。除非你使用了一些处理代码的框架,否则这将不起作用 –

+0

Thx,我用下面的答案来构建它。我发现解决方案非常有趣,如果它工作:) http://stackoverflow.com/a/9441158 –

+0

该解决方案是在伪代码。你需要适应JS和你的特定情况(仍然不会工作,因为它只会突出显示链接,但不会显示内容) –

回答

0

您想要做的一种可能的JavaScript解决方案是触发由参数指定的链接上的点击事件。它的工作是这样的:

  • 从URL读取参数(你可以使用这个solution by Haim Evgi
  • 的链接已经被显示在页面上后,触发点击相应的链接。

这将是一个示例代码:

<ul class="nav nav-pills nav-stacked col-xs-12 col-md-4"> 
    <li><a href="#tab_a" data-toggle="pill" style="font-weight:500;">BÜHNENBAU<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
    <li><a href="#tab_b" data-toggle="pill" style="font-weight:500;">HÖHENARBEITEN<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 26px;color: #db001b;">+</span></a></li> 
    <li><a href="#tab_c" data-toggle="pill" style="font-weight:500;">AUDIO-, VIDEO-, LICHTTECHNIK<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
    <li><a href="#tab_d" data-toggle="pill" style="font-weight:500;">STUDIO<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
    <li><a href="#tab_e" data-toggle="pill" style="font-weight:500;">SONDERLÖSUNGEN<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
    <li><a href="#tab_f" data-toggle="pill" style="font-weight:500;">INSTALLATIONEN<span style="font-weight:500; float:right;font-weight: 700;float: right;font-size: 23px;color: #db001b;">+</span></a></li> 
</ul> 

<script type="text/javascript"> 

// function from https://stackoverflow.com/a/979997/3695983 
function gup(name, url) { 
    if (!url) url = location.href 
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
    var regexS = "[\\?&]"+name+"=([^&#]*)"; 
    var regex = new RegExp(regexS); 
    var results = regex.exec(url); 
    return results == null ? null : results[1]; 
} 

// get the value of the activeTab parameter 
var targetTab = gup("activeTab", window.location.href); 

// trigger the click so that tab activates and shows content 
$("a[href='#" + targetTab + "']").click(); 

</script>