doutang1946 2016-08-13 20:53
浏览 42
已采纳

JavaScript(colorbox)不能通过.load()jquery在加载的内容中工作

I found some related question, unfortunately I couldn't fix my code.

Brief:-
- I have a form in a "Colorbox" window, when I submit the form, I reload .. div id="reload" .. in the parent window to display the new submitted data.
- parent window is updated successfully and new data is loaded.


Issue:-
After loading the new data into the parent window via .load .. URLS with "Colorbox" class doesn't work as "Colorbox" links (work as normal links - open in full page).
- These links work properly before .load() new data
- I need these links to open with "Colorbox" after the .load


1. Parent Page:

            <script>
            $(document).ready(function ()
            {
            $(".popup_class1").colorbox({iframe:true, innerWidth:1100, innerHeight:550,
            overlayClose:true
            });

            });
            </script>

            <div id='reload'>
            <!-- data to be reloaded after submitting the form in the colorbox window -->
            <a href='sales_cc_item_edit.php?id_cci=$id_cci' class='popup_class1'>EDIT</a>
            </div>


2. Colorbox Page:
This page has a form ... after submitting the form AJAX success has a code to reload div in the parent page.

            <script>
                $(function() {
                    $.ajax({
                        url: "sales_action.php",
                        type: "post",
                        data: $(this).serialize(),
                        success: function () {

                            parent.$('#reload').load(parent.document.URL + ' #reload');

                        }
                    });
                });
            </script>


Your help highly appreciated.

  • 写回答

1条回答 默认 最新

  • doudian6229 2016-08-14 12:01
    关注

    After load() you need to reinitialize colorbox for newly created ".popup_class1". Also add ".popup_class1" to load link since without it you'll have double #reload in your parent.

    Try this:

    parent.$('#reload').load(parent.document.URL + ' #reload .popup_class1',
            function(){
                parent.$(".popup_class1").colorbox({iframe:true, innerWidth:1100, innerHeight:550,overlayClose:true});
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办