定制手风琴 - 使用每个

时间:2008-11-23 01:08:27

标签: jquery accordion

我正在尝试为我的页面创建一个自定义手风琴来显示我的帖子。我使用HTML以列表格式使用它,并且当您单击每个标题以展开以显示更多信息时,我正在尝试创建效果。

但我不想为页面上的六个<li>元素说六个代码块。

有没有办法通过.each();也许?而不是创建每个部分?尝试更有活力的方法。

2 个答案:

答案 0 :(得分:3)

你看过this tutorial吗?

因为,example illustrates,不需要多个条件来实现这一点。

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
  //hide the all of the element with class msg_body
  $(".msg_body").hide();
  //toggle the componenet with class msg_body
  $(".msg_head").click(function()
  {
    $(this).next(".msg_body").slideToggle(600);
  });
});
</script>
  

加载页面时,所有具有类名“msg_body”的元素都会折叠。

     

jQuery的“slideToggle()”函数用于扩展和折叠类“msg_body”的“div”。

     

当用户点击带有“.msg_head”类的元素时,然后在其旁边使用“msg_body”类进行div,使用滑动效果进行切换,使用jQuery进行切换面板。

答案 1 :(得分:1)