我正在尝试在点击时替换 div。为此,我正在使用以下脚本
$(function(){
var $containers = $("#center > div").hide();
$('div span a').each(function(i,el){
var idx = i;
$(this).click(function(e){
var $target = $containers.filter(':eq(' + idx + ')');
// Fade out visible div
if($containers.filter(':visible').not($target).length){
$containers.filter(':visible').fadeOut();
}
// Fade in new div if not already showing
$target.not(':visible').fadeIn();
e.preventDefault();
})
})
});
html代码是
<div>
<div>
<span><a href="#">Home</a></span>
<span><a href="#">About us</a></span>
<span><a href="#">Specifications</a></span>
<span><a href="#">Contact us</a></span>
</div>
<div id="center">
<div class="container">
Hey , this is Home div contents
</div>
<div class="container">
Hey , this is About us div contents
</div>
<div class="container">
Hey , this is Specifications div contents
</div>
<div class="container">
Hey , this is Contact us div contents
</div>
</div>
</div>
这里所有的 div 最初都是隐藏的。我想在点击时显示第一个 div 和其他 div
请帮忙,
谢谢