这是一个经过略微修改的示例文件,当您选择仅"core"和"accordion"选项从http://jqueryui.com/download 下载定制的JQuery UI构建文件时,您可以获得该文件。
<!DOCTYPE html>
<html>
<head>
<link type="text/css" href="css/smoothness/jquery-ui-1.7.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.custom.min.js"></script>
<script type="text/javascript">
$(function(){
// Accordion
$("#accordion").accordion({ header: "h3" });
// can be done somewhere later in the code, after init
$( #accordion ).accordion( activate , "#a2");
});
</script>
</head>
<body>
<h2 class="demoHeaders">Accordion</h2>
<div id="accordion">
<div>
<h3 id="a1"><a href="#">First</a></h3>
<div>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</div>
</div>
<div>
<h3 id="a2"><a href="#">Second</a></h3>
<div>Phasellus mattis tincidunt nibh.</div>
</div>
<div>
<h3 id="a3"><a href="#">Third</a></h3>
<div>Nam dui erat, auctor a, dignissim quis.</div>
</div>
</div>
</body>
</html>
选择器参数必须与您指定为“header”的元素匹配 - 在此示例中,它是具有ID的H3标记。运行此代码应该会打开第二个窗格。另一种方法是使用“active”选项在init中指定活动窗格:
<script type="text/javascript">
$(function(){
$("#accordion").accordion({ header: "h3", active :"#a2" });
});
</script>