单击链接会在同一页面上的不同Div中显示它

dad*_*ona 0 javascript css php

我想知道是否有办法能够点击导航Div标签上的链接并将其显示在内容Div上,就像我有

<div id="nav">
<a href="infoto (div id="content")">a link </a></div>
<div id="content>show the stuff</div> 
Run Code Online (Sandbox Code Playgroud)

根据以下评论 - OP表示如下:

我正在尝试重做一个网站,但我的想象力正在变得更好.如果我有三个链接,如家,关于作者,关于我们的使命.我希望能够点击关于作者,并在main_content div标签中显示关于author.html的html文件

小智 8

Alt 1:使用jquery选项卡: 请参阅此处的演示和代码:http://jqueryui.com/demos/tabs/

Alt 2:在同一个html文件中隐藏/显示div:

HTML:

<div id="nav">
    <a href="#content1">Show content 1</a>
    <a href="#content2">Show content 2</a>
    <a href="#content3">Show content 3</a>
</div>

<div id="content1" class="toggle" style="display:none">show the stuff1</div> 
<div id="content2" class="toggle" style="display:none">show the stuff2</div>
<div id="content3" class="toggle" style="display:none">show the stuff3</div>
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$("#nav a").click(function(e){
    e.preventDefault();
    $(".toggle").hide();
    var toShow = $(this).attr('href');
    $(toShow).show();
});
Run Code Online (Sandbox Code Playgroud)

演示:http://jsfiddle.net/5NEu3/3/

Alt 3:从服务器ondemand加载:

要将html加载到主div中,您应该使用:http://api.jquery.com/load/ 关注该站点上的示例.请注意,您加载的html端必须与托管新页面的域相同.

HTML

<a href="http:www.test.com/test1.html">Show content 1</a>
<a href="http:www.test.com/test2.html">Show content 2</a>
Run Code Online (Sandbox Code Playgroud)

jQuery的

$("#nav a").click(function(e){
        e.preventDefault();
        $('#maindiv').load($(this).attr("href"));
});
Run Code Online (Sandbox Code Playgroud)