在页面加载后打开jQuery UI手风琴中的所有部分

时间:2016-11-07 10:41:15

标签: javascript jquery html jquery-ui

您好我想在页面加载后打开jQuery Ui的手风琴。为此,我在本网站上找到了以下代码。

<!doctype html>
<html lang="en">
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="icon" type="../image/logo.png" href="image/logo.png" />
      <title>Survey</title>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
      <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
      <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
      <script type="text/javascript">
          $( function() {
                $('#accordion').accordion({
                        collapsible:true,
                        heightStyle: 'content',
                        beforeActivate: function(event, ui) {
                             // The accordion believes a panel is being opened
                            if (ui.newHeader[0]) {
                                var currHeader  = ui.newHeader;
                                var currContent = currHeader.next('.ui-accordion-content');
                             // The accordion believes a panel is being closed
                            } else {
                                var currHeader  = ui.oldHeader;
                                var currContent = currHeader.next('.ui-accordion-content');
                            }
                             // Since we've changed the default behavior, this detects the actual status
                            var isPanelSelected = currHeader.attr('aria-selected') == 'true';

                             // Toggle the panel's header
                            currHeader.toggleClass('ui-corner-all',isPanelSelected).toggleClass('accordion-header-active ui-state-active ui-corner-top',!isPanelSelected).attr('aria-selected',((!isPanelSelected).toString()));

                            // Toggle the panel's icon
                            currHeader.children('.ui-icon').toggleClass('ui-icon-triangle-1-e',isPanelSelected).toggleClass('ui-icon-triangle-1-s',!isPanelSelected);

                             // Toggle the panel's content
                            currContent.toggleClass('accordion-content-active',!isPanelSelected)    
                            if (isPanelSelected) { currContent.slideUp(); }  else { currContent.slideDown(); }

                            return false; // Cancel the default action
                        }
                    });
                    $("#accordion> div").accordion({
                        header: "h3",
                        autoHeight: false,
                        collapsible: true,
                        icons: icons
                    });
            });
      </script>
    </head>
    <body>
        <div id="accordion">
          <h3>First header</h3>
          <div>First content panel</div>
          <h3>Second header</h3>
          <div>Second content panel</div>
        </div>
    </body>

我很难关注如何在页面加载后打开所有手风琴即使所有事情都是正确的。 谢谢!

1 个答案:

答案 0 :(得分:0)

只需显示手风琴内容,如下所示:

&#13;
&#13;
<!doctype html>
<html lang="en">
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="icon" type="../image/logo.png" href="image/logo.png" />
      <title>Survey</title>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
      <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
      <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
      <script type="text/javascript">
          
      </script>
    </head>
    <body>
        <div id="accordion">
          <h3>First header</h3>
          <div>First content panel</div>
          <h3>Second header</h3>
          <div>Second content panel</div>
        </div>
    </body>
&#13;
public void setVisible(boolean b)
&#13;
&#13;
&#13;