【问题标题】:Product Page Tabs Not Staying产品页面标签不保留
【发布时间】:2014-04-07 22:08:37
【问题描述】:

我在我的网站上安装了产品页面选项卡,它们看起来很棒,直到您单击其他选项卡之一并且选项卡本身消失了。运输选项卡中的内容已更新,一旦我弄清楚如何在您单击它们之间时让选项卡保留在那里,我会将页面底部的产品评论放入评论选项卡。我不确定是什么问题。

这是产品页面的链接,页面上的 jQuery 和 CSS 代码如下。

http://www.sleepfullnights.com/products/sfn-537

jQuery:

$(document).ready(function() {
$('ul.tabs').each(function(){
  var active, content, links = $(this).find('a');
  active = links.first().addClass('active');
  content = $(active.attr('href'));
  links.not(':first').each(function () {
    $($(this).attr('href')).hide();
  });
  $(this).find('a').click(function(e){
    active.removeClass('active');
    content.hide();
    active = $(this);
    content = $($(this).attr('href'));
    active.addClass('active');
    content.show();
    return false;
  });
});

CSS:

<style>
ul.tabs {
  border-bottom: 1px solid #DDDDDD;
  display: block;
  margin: 0 0 20px;
  padding: 0;
}
ul.tabs li {
  display: block;
  float: left;
  height: 30px;
  margin-bottom: 0;
  padding: 0;
  width: auto;
}
ul.tabs li a {
  -moz-border-bottom-colors: none;
  -moz-border-image: none;
  -moz-border-left-colors: none;
  -moz-border-right-colors: none;
  -moz-border-top-colors: none;
  background: none repeat scroll 0 0 #F5F5F5;
  border-color: #DDDDDD !important;
  border-style: solid;
  border-width: 1px 1px 0 1px;
  display: block;
  font-size: 13px;
  height: 29px;
  line-height: 30px;
  margin: 0;
  padding: 0 20px;
  text-decoration: none;
  width: auto;
  color: #303030;
  border-bottom:none !important;
}
ul.tabs li a.active {
  background: none repeat scroll 0 0 #FFFFFF;
  border-left-width: 1px;
  border-top-left-radius: 2px;
  border-top-right-radius: 2px;
  color: #111111;
  height: 30px;
  margin: 0 0 0 -1px;
  padding-top: 4px;
  position: relative;
  top: -4px;
}
ul.tabs li:first-child a.active {
  margin-left: 0;
}
ul.tabs li:first-child a {
  border-top-left-radius: 2px;
  border-width: 1px 1px 0;
}
ul.tabs li:last-child a {
  border-top-right-radius: 2px;
}
ul.tabs:before, ul.tabs:after {
  content: " ";
  display: block;
  height: 0;
  overflow: hidden;
  visibility: hidden;
  width: 0;
}
ul.tabs:after {
  clear: both;
}
</style>

【问题讨论】:

  • 当点击标签时,某些东西会给你的 tabs 类提供 CSS 属性 display:none;
  • 在 Chrome 开发工具中,如果您在“元素”选项卡中右键单击 ul.tabs 并选择“中断 > 属性修改”,它会中断“$(contentLocation).show()。 addClass('active').siblings().hide().removeClass('active');"当你点击一个标签时

标签: jquery css tabs


【解决方案1】:

您的代码似乎正在运行,但您发布的 JS 缺少右括号和括号。

$(document).ready(function() {

$('ul.tabs').each(function(){
  var active, content, links = $(this).find('a');
  active = links.first().addClass('active');
  content = $(active.attr('href'));
  links.not(':first').each(function () {
    $($(this).attr('href')).hide();

  });
  $(this).find('a').click(function(e){
    active.removeClass('active');
    content.hide();
    active = $(this);
    content = $($(this).attr('href'));
    active.addClass('active');
    content.show();
    return false;
      alert('yep');
  });
});
});

这是工作的 jsfiddle:http://jsfiddle.net/gravitybox/7pHg4/

【讨论】:

  • 你是绝对正确的,它适用于你的 jsfiddle。我将您的代码复制并粘贴到页面中,替换所有 JS 并添加括号和括号,但仍然很难。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-20
  • 2018-04-23
  • 1970-01-01
相关资源
最近更新 更多