Javascript 如何在不单击按钮的情况下打开引导模式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29159315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:56:10  来源:igfitidea点击:

How to open bootstrap modal without button-click?

javascriptjqueryhtmlajaxtwitter-bootstrap

提问by alex_gabriel

I need to popup a bootstrap modal in the success function of ajax in my page.The success function is called when the form is submitted.., so is there any method to popup the bootstrap modal without a button click.I'm a rookie.., please help me out here.. This is my ajax call..

我需要在我的页面的ajax的success函数中弹出一个bootstrap模态。提交表单时调用success函数..,那么有没有什么方法可以在没有按钮点击的情况下弹出bootstrap模态。我是菜鸟..,请在这里帮我.. 这是我的 ajax 调用..

     $("#form").submit(function(e)
   {
       $.ajaxSetup({
           headers:{'X-CSRF-Token' : $('meta[name=_token]').attr('content')}
       });
    e.preventDefault(); //STOP default action
    var postData = $(this).serializeArray();
    console.log(postData);


    var formURL =  "http://localhost:8000/v1/people_roles";

    $.ajax(
    {


        url :formURL ,
        type: "POST",
        data : postData,
        success:function(response, textStatus, jqXHR)
    {

        if(response.parent==1)
        {
            $("#getCode").html(response);
            $("#getCodeModal").modal('show');
             window.location.href="/web/staff/detail.php?id="+response.people_id;
        }
        else
        {
            //console.log(response);
            window.location.href="/web/staff/detail.php?id="+response.people_id;
        }
    }



    });   
    });

and this is my html modal code..

这是我的 html 模式代码..

    <div class="modal fade" id="getCodeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
     <div class="modal-content">
     <div class="modal-header">
         <h4 class="modal-title">Modal title</h4>
     </div>
     <div class="modal-body">
         <p><strong>Lorem Ipsum is simply dummy</strong> text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown
             printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting,
             remaining essentially unchanged.</p>
     </div>
     <div class="modal-footer">
         <button type="button" class="btn btn-white" ng-click="cancel()">Close</button>
         <button type="button" class="btn btn-primary" ng-click="ok()">Save changes</button>
     </div>
   </div>
  </div>
</div>     

回答by JK ABC

$("#getCodeModal").modal('show');

$("#getCodeModal").modal('show');

you can refer to this for more info: How to open a Bootstrap modal window using jQuery?

您可以参考此了解更多信息: How to open a Bootstrap modal window using jQuery?