我使用了一个名为tinyAccordion的小插件,我想改变它的行为,但我真的这样做是为了教自己一些关于手风琴的技巧,我对如何改变它有点无能为力所以手风琴一次只打开一个标签。为了澄清,如果您打开另一个选项卡,那个打开的选项卡将关闭。
我有以下代码:
<script type="text/javascript">
var parentAccordion=new TINY.accordion.slider("parentAccordion");
parentAccordion.init("acc","h6",0,0);
var nestedAccordion=new TINY.accordion.slider("nestedAccordion");
nestedAccordion.init("nested","h6",0,0,"acc-selected");
</script>
这是jsfiddle链接:http://jsfiddle.net/LQsV5/
答案 0 :(得分:3)
您不需要插件,只需尝试我为您编写的这几行:
$('.acc li h3').next('.acc-section').hide();
$('.acc li h3').click(function() {
var el = $(this).next('.acc-section');
check = (el.is(':visible')) ? el.slideUp() : ($('.acc-section').slideUp()) (el.slideDown());
});
它会隐藏已打开的标签,但如果再次点击则会隐藏已打开的标签 如果您有疑问,请询问!
答案 1 :(得分:0)
更改
parentAccordion.init("acc","h6",0,0);
&安培;
nestedAccordion.init("nested","h6",0,0,"acc-selected");
到
parentAccordion.init("acc","h6",1,0);
&安培;
nestedAccordion.init("nested","h6",1,0,"acc-selected");