通过jquery触发bootstrap模式 [英] trigger bootstrap modal via jquery

查看:83
本文介绍了通过jquery触发bootstrap模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到了问题。
我试图通过jquery触发bootstrap模式,但它不起作用。
我尝试过各种方式:
way no1:

got a problem. I am trying to trigger bootstrap modal via jquery and it doesnt work. I tried every way: way no1:

$(document).ready(function(){
    $('#btn').click(function(){
        $('#server_msg_modal').modal('show');
    });
});

方式2:

$(document).ready(function(){
    $('#btn').click(function(){
        $('#server_msg_modal').modal('show');
    });
});

方式3:

$('#server_msg_modal').modal({
    show: 'true'
}); 

一切正常......
请帮助我。

nothing is working... please help me.

推荐答案

你的jQuery函数将点击处理程序添加到按钮,并打开模态窗口应该都有效。请参阅下面的示例。我只建议您查看Chrome的DevTools,看看它的控制台是否有任何JavaScript错误。

Your jQuery function to add the click handler to the button, and to open the modal window should both work. See the example below. I can only suggest you to take a look at for example Chrome's DevTools to see if you have any JavaScript errors in its console.

$(document).ready(function(){
  $('#btn').click(function(){
    $('#server_msg_modal').modal('show');
   });
});

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>

<div class="btn btn-danger" href="#server_msg_modal" data-toggle="modal">using data attribute</div>

<div class="btn btn-danger" id="btn">using jQuery click handler</div>


<div class="modal fade" id="server_msg_modal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Modal title</h4>
      </div>
      <div class="modal-body">
        <p>Modal body</p>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

这篇关于通过jquery触发bootstrap模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆