问题
I am having a lot of trouble trying to open certain J query UI accordion sections from external links. I am calling form functions from hyperlinks.
Links are opening sections but then they click back to original position. any help would be much appreciated. Here the source.
<script>
$(function() {
$( "#accordion" ).accordion({
autoHeight: false,
});
});
</script>
<script>
function Clicked1(){
$("#accordion").accordion('activate' , 0)
}
function Clicked2(){
$("#accordion").accordion('activate' , 1)
}
</script>
<div class="demo">
<a href="" onclick="Clicked1()">OPEN1</a>
<a href="" onclick="Clicked2()">OPEN2</a>
<div id="accordion">
<h3>< href="#section1" >Section 1</a></h3>
<div>
<p>Mauris mauris ante, blandit et, ultrices a, susceros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.</p>
</div>
</div>
</div><!-- End demo -->
回答1:
Based on the API of accordion, you should use:
$( "#accordion" ).accordion({ active: 2 });
http://docs.jquery.com/UI/Accordion
回答2:
I made your example work by putting an actual tag into the href you did the onclick
for, as:
<a href="#section1" onclick="clicked2()">;
回答3:
Write accordion code
collapsible: true
来源:https://stackoverflow.com/questions/5140938/jquery-accordion-activate-from-external-links