我在一个页面上有两个手风琴。目前,我可以使用mysite.htm?panel = 0,mysite.htm?panel = 1,mysite.htm?panel = 2从外部链接打开 Accordion 1 中的特定面板,等。
但是,我无法弄清楚如何从外部页面打开 Accordion 2 中的特定面板。
<link href="../jQueryAssets/jquery.ui.core.min.css" rel="stylesheet" type="text/css">
<link href="../jQueryAssets/jquery.ui.theme.min.css" rel="stylesheet" type="text/css">
<link href="../jQueryAssets/jquery.ui.accordion.min.css" rel="stylesheet" type="text/css">
<script src="../jQueryAssets/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="../jQueryAssets/jquery.ui-1.10.4.accordion.min.js" type="text/javascript"></script>
<div id="Accordion1">
<h3><a href="#">Section 1</a></h3>
<div>
<p>Content 1</p>
</div>
<h3><a href="#">Section 2</a></h3>
<div>
<p>Content 2</p>
</div>
<h3><a href="#">Section 3</a></h3>
<div>
<p>Content 3</p>
</div>
</div>
<p> </p>
<p> </p>
<p> </p>
<div id="Accordion2">
<h3><a href="#">Section 1</a></h3>
<div>
<p>Content 1</p>
</div>
<h3><a href="#">Section 2</a></h3>
<div>
<p>Content 2</p>
</div>
<h3><a href="#">Section 3</a></h3>
<div>
<p>Content 3</p>
</div>
</div>
<p> </p>
<script type="text/javascript">
$(function() {
var defaultPanel = parseInt(getParam('panel'));
$( "#Accordion1" ).accordion(
{active: defaultPanel}
);
});
function getParam(name) {
var query = location.search.substring(1);
if (query.length) {
var parts = query.split('&');
for (var i = 0; i < parts.length; i++) {
var pos = parts[i].indexOf('=');
if (parts[i].substring(0,pos) == name) {
return parts[i].substring(pos+1);
}
}
}
return 0;
};
</script>
<script type="text/javascript">
$(function() {
var defaultPanel = parseInt(getParam('panel'));
$( "#Accordion2" ).accordion(
{active: defaultPanel}
);
});
function getParam(name) {
var query = location.search.substring(1);
if (query.length) {
var parts = query.split('&');
for (var i = 0; i < parts.length; i++) {
var pos = parts[i].indexOf('=');
if (parts[i].substring(0,pos) == name) {
return parts[i].substring(pos+1);
}
}
}
return 0;
};
</script>