【问题标题】:Tabs with Jquery [closed]带有 Jquery 的选项卡 [关闭]
【发布时间】:2019-02-19 05:46:56
【问题描述】:

我正在处理这个页面:https://www.landingpagedude.ca/max-ahg/ 如图所示,我有 3 个选项卡(产品演示、专家聊天会话和虚拟现实!):https://prnt.sc/mmvin2

我希望在单击任何选项卡时,更改选项卡下方的内容,指的是单击的选项卡。

此内容https://prnt.sc/mmvjsn指的是第一个标签:

另外两个可以是任意随机内容。唯一的细节是所选标签必须处于活动状态,并且在将鼠标悬停在标签上时具有相同的样式(悬停)

这是移动端视图:https://prnt.sc/mmvmi1

有意义吗?提前非常感谢您

【问题讨论】:

  • 请在此处以minimal reproducible example 的形式添加相关代码,以edit 形式添加到您的问题中。
  • 您可以使用许多现成的标签插件。一个简短的谷歌搜索会找到很好的结果。你试过什么了?你面临什么问题?我们在这里为您提供帮助,但我们不是研究工作或完整代码解决方案的免费提供者。您实际上并未向我们提出任何问题或描述您希望我们帮助解决的任何困难。

标签: jquery html css


【解决方案1】:

这是取自 w3schools 我刚刚编辑到您正在尝试完成的内容。我建议你在这个主题上做一些研究,看看什么最适合你,因为有像 Boostrap 这样的框架可能会有所帮助。

function openCity(evt, cityName) {
  var i, tabcontent, tablinks;
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("tablinks");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].className = tablinks[i].className.replace(" active", "");
  }
  document.getElementById(cityName).style.display = "block";
  evt.currentTarget.className += " active";
}
/* Style the tab */
.tab {
  overflow: hidden;
  border: 1px solid #ccc;
  background-color: #f1f1f1;
}

/* Style the buttons inside the tab */
.tab button {
  background-color: inherit;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
  font-size: 17px;
}

/* Change background color of buttons on hover */
.tab button:hover {
  background-color: #ddd;
}

/* Create an active/current tablink class */
.tab button.active {
  background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
  display: none;
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-top: none;
}
<h2>Tabs</h2>
<p>Click on images and the contect will apper at the Buttom of it</p>

<div class="tab">
  <button class="tablinks" onclick="openCity(event, 'London')"><img width="50mm" src="https://images.discordapp.net/avatars/485508882475778058/c03979b0f78a5a5ec2badca1f1520f14.png?size=512"></button>
  <button class="tablinks" onclick="openCity(event, 'Paris')"><img width="100mm" src="https://singularityhub.com/wp-content/uploads/2018/10/man-into-virtual-reality-world_shutterstock_519713428-1068x601.jpg"></button>
  <button class="tablinks" onclick="openCity(event, 'Tokyo')"><img width="100mm" src="http://www.chutingstar.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/a/e/aerodyne_pilot_1.jpg"></button>
</div>

<div id="London" class="tabcontent">
  Choose from NSW, VIC or QLD product demonstrations and let us take you on the ultimate product journey.
</div>

<div id="Paris" class="tabcontent">
  <h3>Paris</h3>
  <p>Paris is the capital of France.</p> 
</div>

<div id="Tokyo" class="tabcontent">
  <h3>Tokyo</h3>
  <p>Tokyo is the capital of Japan.</p>
</div>

【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多