0

我正在尝试实现可排序的 jQuery UI 手风琴,但是当我单击第一节时,例如它打开时没有内容,如果我然后单击第二节,则第一节中的内容会尝试加载,但该部分在完全加载之前已关闭,并且第二部分打开时没有内容。

HTML:

<!DOCTYPE html> 
<html lang="en"> 
  <head> 
    <meta charset="utf-8" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>
    <title>History of Le Mans</title>   
    <link rel="stylesheet" type="text/css" href="CSS/common.css">
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
    <script src="JS/common.js"></script>
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
  </head>
  <body>
    <nav>
      <ul id="tabs">
        <li><a href="#" id="tab1" name="#tabContent1" class="activeTab">Home</a></li>
        <li><a href="#" id="tab2" name="#tabContent2">History</a></li>
        <li><a href="#" id="tab3" name="#tabContent3">The Circuit</a></li>
        <li><a href="#" id="tab4" name="#tabContent4">Gallery</a></li> 
        <li><a href="#" id="tab5" name="#tabContent5">Further Reading</a></li>    
      </ul>
    </nav>
    <div id="content">
      <div id="tabContent1"></div>
      <div id="tabContent2">
        <div id="accordion">
          <div class="group">
            <h3>Section 1</h3>
            <div>
              <p>Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p>
            </div>
          </div>
          <div class="group">
            <h3>Section 2</h3>
            <div>
              <p>Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna. </p>
            </div>
          </div>
          <div class="group">
            <h3>Section 3</h3>
            <div>
              <p>Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis. Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui. </p>
              <ul>
                <li>List item one</li>
                <li>List item two</li>
                <li>List item three</li>
              </ul>
            </div>
          </div>
          <div class="group">
            <h3>Section 4</h3>
            <div>
              <p>Cras dictum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia mauris vel est. </p><p>Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </p>
            </div>
          </div>
        </div>
      </div>
      <div id="tabContent3"></div>
      <div id="tabContent4"></div>
      <div id="tabContent5"></div>
    </div>
  </body>
</html>

jQuery:

  $(function () {
    $("#accordion")
      .accordion({
        header: "> div > h3"
      })
      .sortable({
        axis: "y",
        handle: "h3",
        stop: function (event, ui) {
          ui.item.children("h3").triggerHandler("focusout");
        }
      });
  });

jQuery 教程:http: //jqueryui.com/accordion/#sortable

是什么导致了这个问题?

4

2 回答 2

1

这是手风琴在不可见时渲染的问题。您可以在此处看到一个问题,它被列为无法修复。

您的选择是使用选项创建手风琴,或者 在导航到选项卡后{ heightStyle: "content" }调用。$("#accordion").accordion("refresh");

于 2013-02-14T22:01:15.737 回答
0

试试这个代码。

$(function() {
    $( "#accordion" )
        .accordion({
            header: "> div > h3",
            heightStyle: "content"
        })
        .sortable({
            axis: "y",
            handle: "h3",
            stop: function( event, ui ) {
                // IE doesn't register the blur when sorting
                // so trigger focusout handlers to remove .ui-state-focus
                ui.item.children( "h3" ).triggerHandler( "focusout" );
            }
        });
});
于 2013-02-14T21:44:43.093 回答