我正在编辑我的问题,以使其更简单。请看下面的代码:
<div id="tabs">
<ul>
<li><a href="#tabs-a">First</a></li>
<li><a href="#tabs-b">Second</a></li>
<li><a href="#tabs-c">Third</a></li>
</ul>
<div id="tabs-a">Lorem ipsum dolor sit amet, rcitation ullamco laboris nisi</div>
<div id="tabs-b">et ornare, felis. Maecenas scelerisque sem non nisl. Fusce</div>
<div id="tabs-c">interdum eget, sagittis et, consequat vestibulum, lacus.</div>
</div>
上面的标签式浏览在jQuery的帮助下运行良好 现在,我想在同一页面中访问带有一些外部链接的选项卡,例如:
<div class="container">
<a href="#tabs-a">First</a>
<a href="#tabs-b">Second</a>
<a href="#tabs-c">Third</a>
<div>
但它不起作用。请帮忙!
答案 0 :(得分:0)
$("#atabs1").click(function () {
$("#tabs-a").css("display", "block");
$("#tabs-b").css("display", "none");
$("#tabs-c").css("display", "none");
$("#tabs-d").css("display", "none");
});
$("#atabs2").click(function () {
$("#tabs-a").css("display", "none");
$("#tabs-b").css("display", "block");
$("#tabs-c").css("display", "none");
$("#tabs-d").css("display", "none");
});
$("#atabs3").click(function () {
$("#tabs-a").css("display", "none");
$("#tabs-b").css("display", "none");
$("#tabs-c").css("display", "block");
$("#tabs-d").css("display", "none");
});
$("#atabs4").click(function () {
$("#tabs-a").css("display", "none");
$("#tabs-b").css("display", "none");
$("#tabs-c").css("display", "none");
$("#tabs-d").css("display", "block");
});
答案 1 :(得分:0)
我为了方便而改变了你的代码。
我已经更改了你的div的id,以便在jquery部分变得容易。
您的div ID已从<div id="tabs-c" class="content">
更改为<div id="databs1" class="content">
,只是为了与li
的ID匹配。
HTML
<div id="tabs">
<ul>
<li><a class ="h" id="atabs1" href="#tabs-a">Goals & Purpose</a></li>
<li><a class ="h" id="atabs2" href="#tabs-b">The Gaps...</a></li>
<li><a class ="h" id="atabs3" href="#tabs-c">Output</a></li>
<li><a class ="h" id="atabs4" href="#tabs-d">Challenges</a></li>
</ul>
<div id="databs1" class="content">
<h2>Goals & Purpose</h2>
<h3>This page is under construction! Please come back soon!</h3>
</div>
<div id="databs2" class="content">
<h2>The Gaps...</h2>
<h3>This page is under construction! Please come back soon!</h3>
</div>
<div id="databs3" class="content">
<h2>Output</h2>
<h3>This page is under construction! Please come back soon!</h3>
</div>
<div id="databs4" class="content">
<h2>Challenges</h2>
<h3>This page is under construction! Please come back soon!</h3>
</div>
Jquery
$('.h').click(function(){
var a = this.id;
a = 'd'+a;
$(".content").css("display", "none");
$('#'+a).css("display", "block");
});
我希望上面的代码可以帮到你,我希望你能实现这个目标。
这是
<强> Demo 强>