bootstrap模拟弹出页面的demo

2025-10-25 15:30:37

1、引入bootstrap相应的js,以及jquery;使用外部引入;

<head>

<meta charset="utf-8"> 

<title>Bootstrap 实例弹出页面实例</title>

<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>

<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

</head>

bootstrap模拟弹出页面的demo

2、button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">

开始演示模态框

</button>

<div id="img"></div>

<!-- 模态框(Modal) -->

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

<div class="modal-dialog">

bootstrap模拟弹出页面的demo

3、<div class="modal-content">

<div class="modal-header">

<button id="modelClose" type="button" class="close" data-dismiss="modal" 

aria-hidden="true">×

</button>

<h4 class="modal-title" id="myModalLabel">

模态框(Modal)标题

</h4>

</div>

<div class="modal-body">

按下 ESC 按钮退出。

</div>

bootstrap模拟弹出页面的demo

4、<div class="modal-footer">

<button type="button" class="btn btn-default" 

data-dismiss="modal">关闭

</button>

<button id="model" type="button" class="btn btn-primary">

提交更改

</button>

</div>

</div>

</div>

</div>

bootstrap模拟弹出页面的demo

5、<script>

$(function(){

$('#model').click(function(){

$("#modelClose").click();

$("#img").append("<div style='height: 100px;width: 100px; background-color: #aaa;'><img src='img/timg.gif' style='height: 100px;width: 100px;'></div>")

})

})

</script>

bootstrap模拟弹出页面的demo

6、如果想要一个页面有两个弹窗,并且弹出不同的内容;

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#2">

需要设置data-target ,这里可以把他理解成id;

<div class="modal fade" id="2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

和这个id属性一一对应,即可实现点击第二个弹出不同页面;

bootstrap模拟弹出页面的demo

7、记录方法,仅供参考;

bootstrap模拟弹出页面的demo

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢