Jquery accordion activate from external links

こ雲淡風輕ζ 提交于 2019-12-25 03:58:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!