doutandusegang2961 2013-07-27 10:10 采纳率: 0%
浏览 62
已采纳

jquery手风琴不起作用

I use accordion box comes from Jquery UI. It doesnt work.

  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

Here is the event handler I use accodion box

$("#skillcat").click(function(e) {
                //var submit_val = new Array();
                //$('#accordion1').accordion('destroy');
                e.preventDefault();
                var ids = [];
                var el = $('[name*=check_subjects]:checked'); //Get all checked Checkboxes
                el.each(function () {
                    ids.push($(this).attr('id')); //get the Id from each checkbox
                });

                $.ajax( {
                type : "POST",

                dataType : "json",
                //
                url : "./wp-admin/admin-ajax.php",
                data : {
                    action : 'each_category',
                    check_subjects : ids
                },
                success : function(data) {
                            alert(data);

                    $('#accordion1').html(data);
                    $("#accordion1").accordion({ active: 0 });
                    $("#accordion1").css("font-family", "'Trebuchet MS', Arial, Helvetica, sans-serif");
                    $("#accordion1").css("font-size", "0.9em");



                    }
            });
        });

place that I suppose to render accodion

   <div id="accordion1" >


    </div>

However, when I click the button first time I get the data to alert box. It render conent but it doesn't apply accodion box. I have another accordion on same page but it works.

If I click another button on same page and try submitting above button, I get data to alert but it won't render the html to browser.

where I have done the mistake?

Ajax is working.

Update

when I add this code

$('#accordion1').accordion('destroy');

before

$('#accordion1').html(data);

Accodion starts to work. But as usual it isnot working second time.

  • 写回答

1条回答 默认 最新

  • doudundian9558 2013-07-28 11:58
    关注

    All jQuery UI plugins maintain state, such as the current option values, whether the plugin is enabled or disabled, which plugins have been initialized on the element, etc. This state persists from the time the plugin is instantiated on the element until it is destroyed, either explicitly by the user calling .pluginName('destroy') or by removing the element (or one of its ancestors) via .remove(). Because of this state management, you cannot instantiate the same plugin on an element multiple times, unless you destroy the plugin instance first.

    Please check following link for more inormation help link

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?