开发者社区 问答 正文

Accordion加载了内容以后 无法加载jquery的accordion效果

 <script>
    $(document).ready(function(){
    $('#accordion').accordion({collapsible: true,active:false,heightStyle: 'content',event: 'click hoverintent'});
    $('#category a').click(function(){
    var page =$(this).attr('href');
    $('#accordion').load('../php/'+page+'.php').accordion('refresh');              
    
    return false;
    });
    });

内容显示正常(accordion的效果在第一次加载的时候也正常),但是accordion的效果会在load新的内容之后失去(php出来的内容正常,就是失去了jqueryui的accordion的效果)。我尝试用destroy和重新加载一个新的accordion但是依然没办法。

展开
收起
小旋风柴进 2016-05-31 09:48:28 1950 分享 版权
1 条回答
写回答
取消 提交回答
  • $(document).ready(function() {
      $('#accordion').accordion({
        collapsible: true,
        active: false,
        heightStyle: 'content',
        event: 'click hoverintent'
      });
      $('body').on('click', '#category a', function() {
        var page = $(this).attr('href');
        var php = $('#accordion').load('../php/' + page + '.php', function() {
          $('#accordion').accordion('destroy').accordion({
            collapsible: true,
            active: false,
            heightStyle: 'content',
            event: 'click hoverintent'
          });
        });
        return false;
      });
    2019-07-17 19:21:21
    赞同 展开评论