主要的代码分为两块,一个是CSS定义模态框,另一个是在Ajax中弹出模态框。

查看菜鸟教程中的模态框教程demo,http://www.runoob.com/try/try.php?filename=bootstrap3-plugin-modal点击打开链接

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Bootstrap 实例 - 模态框(Modal)插件</title>
<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body> <h2>创建模态框(Modal)</h2>
<!-- 按钮触发模态框 -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
开始演示模态框
</button>
<!-- 模态框(Modal) -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
模态框(Modal)标题
</h4>
</div>
<div class="modal-body">
在这里添加一些文本
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭
</button>
<button type="button" class="btn btn-primary">
提交更改
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
</body>
</html>

  

注意:<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">是写在<body>下一级的。

这里的按钮<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">开始演示模态框</button>触发模态框。

我的项目中用的代码:

css部分:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog"  aria-hidden="true" data-backdrop="true" >
<div class="modal-dialog" style="display: outline-block;"><span style="font-family: Arial, Helvetica, sans-serif;"><!--设置模态框属性--></span> <div class="modal-content" style="width: 400px;height: 80px;margin-top: 220px;margin-left: 130px;"><!--设置模态框content属性-->
<div class="modal-header" style="text-align:left;font-size: small;height: 8px;margin-bottom: 5px;">
<!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>-->
<p style="margin-top: -10px;">正在测试数据库连接</p>
</div>
<div class="modal-body" style="text-align: center;font-size: large;height: 18px;">
<p style="margin-top: -15px;">连接中,请稍候...</p>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>

  触发部分:

$.ajax({
type: 'POST',
url: 'api/manager/resource/connect/testConnect',
data: {dbTypeId: dbTypeId, jdbcIp: jdbcIp, jdbcPort: jdbcPort, dbName: dbName, uName: uName, uPwd: uPwd, datadbType: dbType, dbVersion:dbVersion} ,
dataType: 'json',
beforeSend: function(){ //ajax发送请求时的操作,得到请求结果前有效
$('#myModal').modal({
backdrop:'static' //<span style="color:#FF6666;">设置模态框之外点击无效</span>
});
$('#myModal').modal('show'); //弹出模态框
},
complete: function(){ //ajax得到请求结果后的操作
$('#myModal').modal('hide'); //隐藏模态框
},
success: function(msg) {
if (msg.code == 1) {
// jAlert('!', '提示');
$.pnotify({title: "提示",text:"数据库连接正常!",type: 'info', delay: 3000}); } else {
// jAlert(msg.msg, '提示');
$.pnotify({title: "错误",text:msg.msg,type: 'error', delay: 3000});
}
}
});

  https://blog.csdn.net/qq_30629571/article/details/52758842

最新文章

  1. php barcode 制作二条码,隐藏条码的内容,只保留条码
  2. 【JS】点击目标外事件与IFRAM自适应高度
  3. linux查找日志技巧
  4. springmvc 学习笔记_1
  5. 一些有用的Javascript Function :-)
  6. 运用JMX监控Tomcat/Java jvisualvm简要说明
  7. python中关于正则表达式二
  8. 中间人攻击之arp欺骗 科普ARP欺骗
  9. iOS进阶读物
  10. mysql 在windows下的安装,开发基础与要点
  11. ASPF简介
  12. spring mvc 实现文件上传下载
  13. 《JS权威指南学习总结--8.7 函数属性、方法和构造函数》
  14. Jenkins部署的时候报错
  15. python爬虫之Splash使用初体验
  16. Lucene入门学习
  17. C# 窗体间传值
  18. lua去掉字符串中的UTF-8的BOM三个字节
  19. 【转】JS组件系列——Bootstrap组件福利篇:几款好用的组件推荐(二)
  20. 「BJWC2018」Border 的四种求法

热门文章

  1. flex布局快速成型(原创)
  2. 虚拟化技术QEMU-KVM入门
  3. SICP 习题 (1.43)解题总结
  4. 动态记忆网络(DMN)
  5. BAT美团滴滴java面试大纲(带答案版)之四:多线程Lock
  6. show engines 解释
  7. RPC通信原理(未完,先睡觉)
  8. oracle expdp导出时报 ora-39070:无法打开日志文件
  9. Python股票分析系列——基础股票数据操作(一).p3
  10. .net core 2.1 开源项目 COMCMS dnc版本