gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 19:47:18 24 4
gpt4 key购买 nike

我想知道是否有一种方法可以点击导航 Div 标签上的链接并将其显示在内容 Div 上,就像我有过一样

<div id="nav">
<a href="infoto (div id="content")">a link </a></div>
<div id="content>show the stuff</div>

根据下面的评论 - OP 声明如下:

我正在尝试重做一个网站,但我的想象力越来越多。如果我有三个链接,比如主页、关于作者和关于我们的使命。我希望能够点击关于作者,并在 main_content div 标签中显示 html 文件 aboutauthor.html

最佳答案

备选方案 1:使用 jquery 标签:请在此处查看演示和代码:http://jqueryui.com/demos/tabs/

选项 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>

jQuery:

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

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

选项 3:按需从服务器加载:

要将 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>

jQuery

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

关于php - 单击链接在同一页面上的不同 Div 中显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8152976/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com