简体   繁体   English

单击时更改选项卡链接(和已激活的锚)

[英]Change Tab Link on Click (and Already Active Anchor)

Trying to piece together js knowledge as I go here. 我在这里尝试拼凑js知识。 But I have a website that will be relying on a tabbed (just 2) concept to flip between the companies two services. 但是我有一个网站,该网站将依靠选项卡式(仅2个)概念在公司的两种服务之间切换。

So when navigating to the page, they user will be directed to Company1 and I would like to have a tab of Company 2 on the right. 因此,当导航到页面时,他们的用户将被定向到Company1,而我希望在右侧显示Company 2的选项卡。 It will be the same domain, just domain.com#company2. 它将是相同的域,只是domain.com#company2。

When they navigate to Company 2 directly (via domain.com#company2) I would like the tab on the right to link to Company 1. 当他们直接(通过domain.com#company2)导航到Company 2时,我希望右侧的选项卡链接到Company 1。

So basically, it looks like js is the only way to do this. 因此,基本上,看起来js是执行此操作的唯一方法。 Something that could read the active id and style the tab accordingly. 可以读取活动ID并相应设置标签样式的内容。

The main function would be based on click. 主要功能将基于点击。 So if you click the tab, it switches to the non-active companies tab. 因此,如果单击选项卡,它将切换到非活动公司选项卡。

The tab itself will remain the same, all I need to change is the href. 选项卡本身将保持不变,我需要更改的只是href。

Thanks in advance guys! 在此先感谢大家!

I think you could use CSS float : 我认为您可以使用CSS float:

$("#tab1_id").click(function(){
    $(".2tabs_class").css("float","left)
})
$("#tab2_id").click(function(){
    $(".2tabs_class").css("float","right)
})

Make sure 2 tabs are inside a div 确保2个标签位于div中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM