简体   繁体   English

自定义手风琴面板无法正常工作

[英]Custom accordion pannel not working properly

I have this accordion script: 我有这个手风琴脚本:

$(document).ready(function(){
$(function(){
  //  Accordion Panels
  $(".accordion span").hide();

  $(".accordion li").click(function(){
      $(this).next(".pane").slideToggle("fast").siblings(".pane:visible").slideUp("fast");
  });
});
});

and this PHP script: 和这个PHP脚本:

echo "<u>Organizational Chart</u><br/>";
        echo "<div class='accordion'>";
$select_branch=mysql_query("SELECT * FROM branch");
while($result_branch=mysql_fetch_array($select_branch)){
    $branch1=$result_branch[1];
    if($branch1!='TOP'){
        echo "<li>".$branch1."</li>";
        echo "<div class='pane'>";
    }
    $select_department=mysql_query("SELECT * FROM departments");
        while($result_department=mysql_fetch_array($select_department)){
            $department=$result_department[1];
            $parent_department=$result_department[2];
            $select_staff=mysql_query("SELECT * FROM organization WHERE branch='$branch1' AND department='$department'");
                while($result_staff=mysql_fetch_array($select_staff)){
                    $fname=$result_staff[1];
                    $mname=$result_staff[2];
                    $lname=$result_staff[3];
                    $department=$result_staff[4];
                    $branch=$result_staff[5];
                    $position=$result_staff[6];
                    $status=$result_staff[7];
                    $pic=$result_staff[8];
                    echo "
                        <div class='staffDiv'>
                            <img class='staffPic' src='images/upload/".$pic."'/>
                            <div style='clear:both'></div>
                            <div class='staffDetails'>
                                ".$fname." ".$mname." ".$lname."<br/>
                                ".$position."<br/>
                            </div>
                        </div>
                    ";
                }
        }
    if($branch1!='TOP'){
        echo "</div>";
    }
}
        echo "</div>";

when I run the page all the panel is open and when I click one panel, all content will hide and start working properly, how can I fix my code? 当我运行该页面时,所有面板都打开,而当我单击一个面板时,所有内容都将隐藏并开始正常工作,如何修复我的代码? Did I missed something. 我错过了什么吗?

I'm sorry for the long code post, I am hoping that someone can help me with this problem. 对于冗长的代码发布,我感到抱歉,我希望有人可以帮助我解决这个问题。

Try assigning the active property to be false by default. 默认情况下,尝试将active属性分配为false。 For it to work, the collapsible must be true. 为了使其工作,可折叠必须为真。

$( ".accordion" ).accordion({ active: false, collapsible: true });

Refer: http://api.jqueryui.com/accordion/#option-active 请参阅: http : //api.jqueryui.com/accordion/#option-active

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM