在 jQuery 中制作选项卡并显示/隐藏选项卡式内容
所以 tab 可能不是在我的场景中使用的正确词,但情况是这样的(而且我也不想使用 jQuery-UI 库)。我认为可以做得更简单。
标题中的导航标记:
<ul>
<li><a class="active" href="#" title="">Uno</a></li>
<li><a href="#" title="">Dos</a></li>
<li><a href="#" title="">Tres</a></li>
<li><a href="#" title="">Cuatro</a></li>
</ul>
内容的正文标记(它们不包含在同一个 div 中,也不可能包含在同一个 div 中):
<div class="block">
<p>Lorem ipsum</p>
</div>
<div class="block">
<p>Lorem ipsum</p>
</div>
<div class="block">
<p>Lorem ipsum</p>
</div>
<div class="block">
<p>Lorem ipsum</p>
</div>
我正在尝试做两件事。 1.) 隐藏除第一个内容块之外的所有内容(与第一个列表项相对应,因此在加载时为 .active。2.) 单击任何列表项时,它会隐藏所有其他内容块并显示相应的内容一,同时在导航中向其添加 .active 类。
非常感谢您的帮助。
So tab may not be the right word to use in my scenario, but here is the situation (and I don't want to use jQuery-UI library too). I think it can be done more simply.
Nav markup in the header:
<ul>
<li><a class="active" href="#" title="">Uno</a></li>
<li><a href="#" title="">Dos</a></li>
<li><a href="#" title="">Tres</a></li>
<li><a href="#" title="">Cuatro</a></li>
</ul>
Body markup for the content (they are not contained in the same div, nor can they be):
<div class="block">
<p>Lorem ipsum</p>
</div>
<div class="block">
<p>Lorem ipsum</p>
</div>
<div class="block">
<p>Lorem ipsum</p>
</div>
<div class="block">
<p>Lorem ipsum</p>
</div>
I'm trying to do two things. 1.) Hide everything except the first block of content (which corresponds with the first list item, hence .active, on load. 2.) On click of any of the list items it hides all the other blocks of content and shows the appropriate one, while adding an .active class to it in the nav.
Would really appreciate the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导航链接....
您的部分代码....
上面的 html 的 jquery 代码可能是这样的...
尝试这个...它会工作...让我知道...
Navigation links....
Code for you sections....
your jquery code for above html could be like this...
try this... it will work... let me know...