我正在尝试使用jQuery制作可点击的选项卡
I am trying to make clickable tabs using jQuery
我正在尝试使用JavaScript制作可点击的标签,当我当前点击标签时,一切都消失了。有什么建议吗?
HTML:
<div id="contentwrap" class="round">
<h1>About Eclipse</h1>
<div class="tabs">
<ul class="tabsnav cf">
<li><a href="#ct-who">who we are</a></li>
<li><a href="#ct-what">what we do</a></li>
<li><a href="#ct-how">how you can join</a></li>
</ul>
<div class="tab" id="ct-who">
<p>Eclipse is a fake JavaScript community website being provided as a design element for students in the WDDBS SFWO course.</p><p>And yes, I realize this is also the name of a popular editor; but JS developers don't need that, because we're too rockstar for it. Instead, this name represents what your earned skill will accomplish for you.. eclipse the competition.</p><p>PS - The cake is not a lie.</p>
</div>
<div class="tab" id="ct-what">
<p>What we do is undefinable, not because there is no data type or testable typeof operator for our work, but because no words can describe the awesomeness of JavaScript coding joy once you've reached enlightenment. Learn to revel in the beauty of the language, and great power shall be bestowed upon you.</p>
<p><img src="#" /></p>
</div>
<div class="tab" id="ct-how">
<p>You've already joined our elite ranks. Now prove thee knoweth jquery.</p>
</div>
</div>
</div>
JavaScript:
$('#contentwrap p').hide().eq(0).show();
$('#contentwrap p:not(:first)').hide();
$('#contentwrap ul li').click(function(event) {
event.preventDefault();
$('p').hide();
$('#contentwrap .current').removeClass("current");
$(this).addClass('current');
var clicked = $(this).find('a:first').attr('href');
$('#ct-how, #ct-what, #ct-who ' + clicked).fadeIn('400');
}).eq(0).addClass('current');
您的fadeIn
方法没有选择单击的元素。此外,您还隐藏了<p>
元素,并试图在它们的容器中淡入。试试这个:
$('#contentwrap ul li').click(function(event) {
event.preventDefault();
$('p').hide();
$('#contentwrap .current').removeClass("current");
$(this).addClass('current');
var clicked = $(this).find('a:first').attr('href');
$(clicked).find('p').fadeIn('400');
}).eq(0).addClass('current');
演示
相关文章:
- 按照选项卡索引的顺序循环一个jQuery选择
- 如何在使用selectBoxIt JQuery插件时检测选项更改
- JQuery覆盖不更改单选选项
- jQuery动态表单显示在select选项上
- Jquery:如何获取所选选项全文(带空格)
- 使用基于文本的 Jquery 选择选项
- 如果类不是一个选项,如何在使用 jQuery 时控制(避免)嵌套 html 元素的样式
- 使用纯javascript而非jquery使所选选项卡处于活动状态并保持非活动状态
- 阻止选项卡缓存jquery ui
- 使用Jquery增加选项卡
- 如何在jquery.easytabs.js中获取当前选项卡
- JQuery-停止手风琴链接关闭所有选项卡
- 设置所选选项JQuery
- 防止已选择的选项 Jquery 使用 MYSQL 自动完成
- 动态替换下拉菜单选项jQuery
- 在Chrome和Firefox中选择选项jquery 2.1.1时出错
- 附加逗号分隔的值以选择选项 jQuery
- 忽略选择选项jQuery的值
- 无法在回调时配置选项(jQuery插件)
- 为什么这个自动选择第一个选项jquery脚本在Internet Explorer中不起作用