简体   繁体   English

jQuery Multi Tabs脚本不起作用

[英]jQuery Multi Tabs Script Not Working

This is the pen I'm working on but the the content of each tab do not update please check the jQuery I've coded below. 这是我正在处理的笔 ,但每个选项卡的内容都没有更新,请检查我在下面编写的jQuery。

$('.content-canvas').find('div').hide();
$('.content-canvas div:first-child').show();
$('.tab-button span:first-child').addClass('active');
$('.tab-button').find('span').click(function(){
   $('.tab-button').find('span').removeClass('active');
   $(this).addClass('active');
   var currentclass=$('.active').attr('class');
   $('.content-canvas').find('div').each(function(){
      if($(this).attr('class')==currentclass) {
         $('.content-canvas').find('div').hide();
         $(this).show();
      }
      else {
         $(this).hide();
      }
   });
});

The problem is that currentclass is being set to something like "content2 active" instead of "content2". 问题是currentclass被设置为类似“content2 active”而不是“content2”。

You can try using something like this: 您可以尝试使用以下内容:

var currentclass = $(this).attr('class');  
$(this).addClass('active');

See: http://codepen.io/anon/pen/qbAdG 请参阅: http//codepen.io/anon/pen/qbAdG

This is why having a debugger is helpful. 这就是调试器有用的原因。 You can use a debugger to trace through the code and check the values of variables and the execution path to verify that everything is behaving as it should. 您可以使用调试器跟踪代码并检查变量的值和执行路径,以验证一切都按预期运行。

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

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