Hello Stackers,
我现在遇到另一个问题,这次是一个问题,我甚至不知道如何启动代码。我有3个链接,还有4个div。一个DIV是默认值,其他则是单击链接时。只是,我希望它隐藏并用jQuery显示div,我不擅长。
我知道这不会对锚点起作用,或者它会起作用吗?
<a href="#div1">SHOW DIV1</a>
<a href="#div2">SHOW DIV2</a>
<a href="#div3">SHOW DIV3</a>
<div id="default">Default Content</div>
<div id="1">DIV 1 Content</div>
<div id="2">DIV 2 Content</div>
<div id="3">DIV 3 Content</div>
这甚至可能吗?
答案 0 :(得分:1)
试试这个:
$().ready(function(){
$('div').not('#default').hide(); // hide all divs except for 'default' on page load
$('a').click(function(e) // bind a click event on the anchor tags
{
$('div').not('#default').hide();; // hide all divs except for 'default'
e.preventDefault();
var container = $(this).attr('href').replace('#div',''); // find the corresponding div to show using the 'href' attribute
$("#" + container).show(); // show that div
});
});