我正在尝试实现可排序的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
是什么导致了这个问题?
答案 0 :(得分:1)
这是手风琴在不可见时呈现的问题。您可以看到问题here,它列为无法修复。
您的选择是使用选项{ heightStyle: "content" }
创建手风琴,或者在导航到选项卡后调用$("#accordion").accordion("refresh");
。
答案 1 :(得分: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" );
}
});
});