weixin_33712987 2017-06-23 07:53 采纳率: 0%
浏览 11

重建模态列表

I am creating a set of pages which have sections loaded dynamically by ajax.

Each loaded ajax page is just html content and contains a modal.

I have tinyMCE editors which had the same problem but I have fixed that one by clearing all editors from the editors array and reloading them.

tinyMCE.editors = [];
tinyMCE.init();

I am looking to do something similar with Bootstrap Modals. I understand that the updated DOM is not known about by bootstrap and that placing a script tag at the end would resolve this issue BUT by doing that, it also introduces problems as the scripts will have been previously loaded for previous parts of the page (multiple loads of the same script).

The reason I am looking to do this is this.

  • Create button to open modal
  • Modal opens
  • Click close or the x on the modal, nothing happens

Closing code:

<button type="button" class="close" data-dismiss="modal">&times;</button>

My opening code:

<a href="#" id="adminAdd" class="adminClicks btn btn-sm btn-success" data-toggle="modal" data-target="#addModal">Add<span class="glyphicon glyphicon-plus"></span></a>

Dialog div:

<div id="addModal" class="modal fade" role="dialog">

Any advice would be great. I have used a modal which works correctly at the highest level where the page is not changed by ajax.

  • 写回答

1条回答 默认 最新

  • weixin_33692284 2017-06-23 13:28
    关注

    I figured out a workaround instead.

    So in the static code which isnt affected by jquery I have created this:

    <div id="customModal" class="modal fade" role="dialog">
        <div class="modal-dialog">
    
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title" id="customModalHeader"></h4>
                </div>
                <div class="modal-body" id="customModalBody">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary pull-left">Add</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
    
        </div>
    </div>
    

    Then I just apply using jQuery any changes I require. I added Id's to the changeable fields so I adjust by:

    $("customModalHeader").html("My custom header"); 
    

    in the ajax loaded section between script tags. I could probably include a script file too but this is on the fly changes after all.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP