lbfeng
V2EX  ›  jQuery

bootstrap modal event 多次绑定

  •  
  •   lbfeng · Jun 21, 2016 · 4119 views
    This topic created in 3638 days ago, the information mentioned may be changed or developed.
        <div id="exampleModal"> 。。。</div>
        <button data-toggle="modal" data-target="#exampleModal"></button>
        
        $('#exampleModal').on('show.bs.modal', function(event) {
        	$.ajax(...);
            $(this).modal('hide');
        });
    

    第一次打开窗口会有一次 ajax ,不刷新,第二次打开窗口会有两次 ajax 。是因为$('#exampleModal')重复捆绑 modal 。怎样才能在不刷新前提下多次打开窗口但只绑定一个 modal 。

    Supplement 1  ·  Jun 21, 2016
    已搞定
    3 replies    2017-03-12 18:42:25 +08:00
    fising
        1
    fising  
       Jun 21, 2016 via iPhone
    每次都先 unbind ,应该有更好的办法
    fising
        2
    fising  
       Jun 22, 2016
    @lbfeng 怎么解决的呢
    xx19941215
        3
    xx19941215  
       Mar 12, 2017
    怎么弄的,我也遇到了类似的情况!!!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   921 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:38 · PVG 06:38 · LAX 15:38 · JFK 18:38
    ♥ Do have faith in what you're doing.