使用定位点的jQuery multiple div show hide函数

使用定位点的jQuery multiple div show hide函数,jquery,html,hide,anchor,show,Jquery,Html,Hide,Anchor,Show,我想使用相关链接通过锚点打开div。当我点击链接时,相关div显示,但当我点击其他链接时,上一个div也显示 我想通过锚点打开相关链接上的div,但当我单击其他链接时,上一个div需要关闭。在所有链接和相关div中相同。请帮助我您需要像这样隐藏单击回调中的所有div var tabs = $('ul.menu li a'); tabs.bind('click',function(event){ var $anchor = $(this); var ids

我想使用相关链接通过锚点打开div。当我点击链接时,相关div显示,但当我点击其他链接时,上一个div也显示


我想通过锚点打开相关链接上的div,但当我单击其他链接时,上一个div需要关闭。在所有链接和相关div中相同。请帮助我

您需要像这样隐藏单击回调中的所有div

var tabs = $('ul.menu li a');

    tabs.bind('click',function(event){
        var $anchor = $(this);
        var ids = tabs.each(function(){
           $($(this).attr('href')).hide();   
        });
        $($anchor.attr('href')).fadeIn('slow');
        event.preventDefault();
    });
这里


当用户单击链接时,我首先使用循环隐藏所有div。

您需要像这样隐藏单击回调中的所有div

var tabs = $('ul.menu li a');

    tabs.bind('click',function(event){
        var $anchor = $(this);
        var ids = tabs.each(function(){
           $($(this).attr('href')).hide();   
        });
        $($anchor.attr('href')).fadeIn('slow');
        event.preventDefault();
    });
这里


当用户单击链接时,我首先使用循环隐藏所有div。

或者您可以这样做。。div一个css类到父div和

<div style="width:1000px; height:450px; margin-top:50px;">

<div style="width:350px; height:250px; margin:0 auto;" class="test">
<div id="firstDiv" style="background:#03F; width:350px; height:250px; float:left; display:none;">First Div</div>
<div id="secondDiv" style="background:#06F; width:350px; height:250px; float:left; display:none;">Second Div</div>
<div id="thirdDiv" style="background:#09F; width:350px; height:250px; float:left; display:none;">Third Div</div>
<div id="fourthDiv" style="background:#0CF; width:350px; height:250px; float:left; display:none;">Fourth Div</div>
</div>

为此..

或者您可以这样做。。div一个css类到父div和

<div style="width:1000px; height:450px; margin-top:50px;">

<div style="width:350px; height:250px; margin:0 auto;" class="test">
<div id="firstDiv" style="background:#03F; width:350px; height:250px; float:left; display:none;">First Div</div>
<div id="secondDiv" style="background:#06F; width:350px; height:250px; float:left; display:none;">Second Div</div>
<div id="thirdDiv" style="background:#09F; width:350px; height:250px; float:left; display:none;">Third Div</div>
<div id="fourthDiv" style="background:#0CF; width:350px; height:250px; float:left; display:none;">Fourth Div</div>
</div>

因此,..

另一种可能的解决方案是在淡入元素周围的div上放置一个类或id:

<div style="width:1000px; height:450px; margin-top:50px;">

<div class="fadein" style="width:350px; height:250px; margin:0 auto;">

    <div id="firstDiv" style="background:#03F; width:350px; height:250px; float:left; display:none;">First Div</div>
    <div id="secondDiv" style="background:#06F; width:350px; height:250px; float:left; display:none;">Second Div</div>
    <div id="thirdDiv" style="background:#09F; width:350px; height:250px; float:left; display:none;">Third Div</div>
    <div id="fourthDiv" style="background:#0CF; width:350px; height:250px; float:left; display:none;">Fourth Div</div>

</div>

另一种可能的解决方案是在淡入元素周围的div上放置一个类或id:

<div style="width:1000px; height:450px; margin-top:50px;">

<div class="fadein" style="width:350px; height:250px; margin:0 auto;">

    <div id="firstDiv" style="background:#03F; width:350px; height:250px; float:left; display:none;">First Div</div>
    <div id="secondDiv" style="background:#06F; width:350px; height:250px; float:left; display:none;">Second Div</div>
    <div id="thirdDiv" style="background:#09F; width:350px; height:250px; float:left; display:none;">Third Div</div>
    <div id="fourthDiv" style="background:#0CF; width:350px; height:250px; float:left; display:none;">Fourth Div</div>

</div>