How to get twitter bootstrap modal to close (after initial launch)

前端 未结 10 941
半阙折子戏
半阙折子戏 2020-12-24 04:13

I\'m very much a noob, so I think I\'m overseeing something (probably obvious) with twitter bootstrap modal. What I am trying to do is get a modal to launch only on mobile.

10条回答
  •  盖世英雄少女心
    2020-12-24 04:49

    Here is a snippet for not only closing modals without page refresh but when pressing enter it submits modal and closes without refresh

    I have it set up on my site where I can have multiple modals and some modals process data on submit and some don't. What I do is create a unique ID for each modal that does processing. For example in my webpage:

    HTML (modal footer):

     
    

    jQUERY:

    $(document).ready(function(){
    // Allow enter key to trigger preloadorders form
        $(document).keypress(function(e) {       
          if(e.which == 13) {   
              e.preventDefault();   
                    if($(".trigger").is(".ok")) 
                       $("#PreLoadOrders").trigger("click");
                    else
                        return;
          }
        });
    });
    

    As you can see this submit performs processing which is why I have this jQuery for this modal. Now let's say I have another modal within this webpage but no processing is performed and since one modal is open at a time I put another $(document).ready() in a global php/js script that all pages get and I give the modal's close button a class called: ".modal-close":

    HTML:

    
    

    jQuery (include global.inc):

      $(document).ready(function(){
             // Allow enter key to trigger a particular button anywhere on page
            $(document).keypress(function(e) {
                    if(e.which == 13) {
                       if($(".modal").is(":visible")){   
                            $(".modal:visible").find(".modal-close").trigger('click');
                        }
                    }
             });
        });
    

提交回复
热议问题