Jquery手风琴嵌套问题
我在设置两个独立的手风琴时遇到问题。 它们应该独立打开/关闭,并且accordion2应该嵌套在accordion1中(代码见下文)
现在发生的情况是,它们在打开时相互重叠,IE 甚至覆盖了“手风琴 1 下面的文本”。 这不应该发生。
有什么需要改进的想法吗?
非常感谢任何帮助!
干杯
<script type="text/javascript">
$(document).ready(function() {
$("#accordion1").accordion();
$("#accordion2").accordion();
$('#accordion1 .q1').click(function() {
$(this).next().toggle();
return false;
}).next().hide();
$('#accordion2 .q2').click(function() {
$(this).next().toggle();
return false;
}).next().hide();
});
</script>
<style type="text/css">
#sub1 { height:100px; background: #FF0000;}
#sub2 { height:100px; background: #FF00FF;}
</style>
</HEAD>
<BODY>
<div id="accordion1">
<div>
<a class="q1" href="#">
accordion 1
</a>
<div id="sub1">
<div id="accordion2">
<div>
<a class="q2" href="#">
accordion 2
</a>
<div id="sub2">
222222222
</div>
</div>
</div>
text below accordion 2
</div>
</div>
</div>
text below accordion 1
</BODY>
</HTML>
I am having trouble setting up two independent accordions.
They should open / close independently and accordion2 should be nested in accordion1 (code see below)
What happends right now is that they are overlapping each other when opened and IE is even overwriting 'text below accordion 1'. This should not happen.
Any ideas what to improve?
Thanks a lot any help!
Cheers
<script type="text/javascript">
$(document).ready(function() {
$("#accordion1").accordion();
$("#accordion2").accordion();
$('#accordion1 .q1').click(function() {
$(this).next().toggle();
return false;
}).next().hide();
$('#accordion2 .q2').click(function() {
$(this).next().toggle();
return false;
}).next().hide();
});
</script>
<style type="text/css">
#sub1 { height:100px; background: #FF0000;}
#sub2 { height:100px; background: #FF00FF;}
</style>
</HEAD>
<BODY>
<div id="accordion1">
<div>
<a class="q1" href="#">
accordion 1
</a>
<div id="sub1">
<div id="accordion2">
<div>
<a class="q2" href="#">
accordion 2
</a>
<div id="sub2">
222222222
</div>
</div>
</div>
text below accordion 2
</div>
</div>
</div>
text below accordion 1
</BODY>
</HTML>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
#accordian1 > 分区> .q1
而不是#accordian1 .q1
,因为该选择器也匹配第二个手风琴的子级。Use
#accordian1 > div > .q1
instead of#accordian1 .q1
, because that selector also matches the children of the second accordion as well.