我基本上要问的是这个。
<script>
$(function() {
$( "#accordion" ).accordion();
});
</script>
<div id="accordion">
<h3>Section 1</h3><a name="myAnchor"></a>
<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>
<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>
答案 0 :(得分:1)
如果您希望它基于url打开,那么该锚点的href需要在其中具有相同的哈希值,如果这是您想要使用的。
var hash = window.location.hash;
var hashName = hash && hash.replace('#','');
$('.accordionModule .accordionPanel .content a').filter(function(){
return this.hash === hash;
// or
return this.name === hashName;
}).closest('.accordionPanel').find('.trigger').click();
OR
$('.accordionModule .accordionPanel .content a[href$=' + hash +']')
.closest('.accordionPanel').find('.trigger').click();
因此,url = mywebsite.com#myanchor
将匹配<a href="#myanchor"></a>
答案 1 :(得分:1)
示例,如果我理解你想要的功能:
var userUrl = window.location.href.split( '#' )[1];
$('.accordionModule .accordionPanel .content a').each(function( index ) {
if ($( this ).attr('name') == userUrl ) {
var $theTarget = $("a[href='" + userUrl + "']"); //gets the anchor targeted
//then open the corresponding panel
$theTarget.closest('.accordionPanel').find('.trigger').click();
}
});
我希望这就是你所要求的。已经晚了,我累了。洛尔