2012-09-14 260 views
0

我确信这个话题之前已被提及,但在这里。我的尝试是隐藏一个div并将其替换为其他对象。同样,我需要向某个项目添加一个类,同时从另一个类中移除一个类。这很简单,我确定。谢谢显示一个div隐藏另一个

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('.form_sub').hide(); 
     }); 
     </script> 
     <script type="text/javascript"> 
    $('a.theader_t').click(function(){ 
     $('.form_header').show(); 
     $('.form_sub').hide(); 
     $('.theader').addClass('active'); 
     $('sub_theader').removeClass('active'); 
    }); 
    </script> 
    <script type="text/javascript"> 
    $('.sub_theader_t').click(function){ 
    $('.form_header').hide(); 
     $('.form_sub').show(); 
     $('.theader').removeClass('active'); 
     $('sub_theader').addClass('active'); 
    }); 
    </script> 

我的appologies不问问题。第一个功能起作用,最后2个根本不工作。我希望a.theader_t在添加活动类的同时显示.form_header,但如果适用的话,则从sub_theader_t开始活动。再次感谢!

+2

...... _和问题是? – undefined

+0

你的问题是什么? – thecodeparadox

+0

对我来说看起来不错。我有几条评论。 1)您不必为每个功能添加新的脚本标签。你可能在几个不同的地方有这些代码,这就是为什么你将它包含在内的原因,在这种情况下,这很好。 2)我会改变你的2 div有独特的ID,而不是你拥有的课程。选择器然后是$('#form_header')而不是$('。form_header') – ajon

回答

2

其他两个函数不进

$(document).ready(function() { }); 

和第三函数有错误

$('.sub_theader_t').click(function){ to 

$('.sub_theader_t').click(function(){ 
+0

啊啊好眼睛兄弟我完全错过了!万分感谢! – Cam

0

你似乎在这里结束脚本...

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('.form_sub').hide(); 
     }); 
</script> 

事件不在Document.Ready .. Make this modifi并且它应该工作正常..也请务必将这些事件委托给使用.on()

< script type = "text/javascript" > $(document).ready(function() { 
    $('.form_sub').hide(); 

    $('a.theader_t').on('click',function() { 
     $('.form_header').show(); 
     $('.form_sub').hide(); 
     $('.theader').addClass('active'); 
     $('.sub_theader').removeClass('active'); 
    }); 

    $('.sub_theader_t').on('click' ,function) { 
     $('.form_header').hide(); 
     $('.form_sub').show(); 
     $('.theader').removeClass('active'); 
     $('.sub_theader').addClass('active'); 
    }); 
< /script>​​​​​