单击时显示多个元素
HTML:
<ul id="mode">
<li><a href="#tab1">tab1</a>
<div class="extra">tada</div>
</li>
<li><a href="#tab2">tab2</a>
<div class="extra">tada</div>
</li>
</ul>
<div id="tab1" class="tab-content" style="display: none">content 1</div>
<div id="tab2" class="tab-content" style="display: none">content 2</div>
jQuery:
$(function(){
var mode = $('#mode');
var arrow = $('<span/>', {'class': 'arrow'});
$('li a', mode).bind('click.mytabs', function() {
$('li', mode).removeClass('active');
$(this).parent().addClass('active').append(arrow);
var a = $(this).attr('href');
$('.tab-content').hide();
$(a).show();
return false;
}).filter(':first').triggerHandler('click.mytabs'); // eq(0) works as well
});
JSFiddle在这里: http://jsfiddle.net/wwMJL/
我也想单击时显示每个 li 的“额外”div,并在选项卡处于非活动状态时隐藏,我需要在代码中更改什么?
谢谢!
HTML:
<ul id="mode">
<li><a href="#tab1">tab1</a>
<div class="extra">tada</div>
</li>
<li><a href="#tab2">tab2</a>
<div class="extra">tada</div>
</li>
</ul>
<div id="tab1" class="tab-content" style="display: none">content 1</div>
<div id="tab2" class="tab-content" style="display: none">content 2</div>
jQuery:
$(function(){
var mode = $('#mode');
var arrow = $('<span/>', {'class': 'arrow'});
$('li a', mode).bind('click.mytabs', function() {
$('li', mode).removeClass('active');
$(this).parent().addClass('active').append(arrow);
var a = $(this).attr('href');
$('.tab-content').hide();
$(a).show();
return false;
}).filter(':first').triggerHandler('click.mytabs'); // eq(0) works as well
});
JSFiddle here: http://jsfiddle.net/wwMJL/
I'd like to also show each li's 'extra' div on click and hide when the tab is inactive, what do I need to change in the code?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
演示
demo