https://blog.csdn.net/wusd1256/article/details/77880033
Bootstrap Modals 是使用的定制的JQuery 插件创建的,下面是使用方法:
1.1:导入对应的js。css,需要导入bootstrap.js或者bootstrap.min.js文件,bootstrap的前提是jQuery,所以我们要导入jquery.min.js
对应导入代码:
- <!--导入样式-->
- <link href="Bootstrap/css/bootstrap-theme.css" rel="stylesheet"/>
- <link href="Bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" />
- <link href="Bootstrap/css/bootstrap.css" rel="stylesheet"/>
- <link href="Bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
- <!--导入bootstrap.js包-->
- <script src="jquery/jquery-3.1.1.min.js"></script>
- <script src="Bootstrap/js/bootstrap.min.js"></script>
- <strong>1.2:具体用法有2种</strong>
demo如下:
- <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>
2、通过 JavaScript :使用这种技术,您可以通过简单的一行 JavaScript 来调用带有 id="identifier" 的模态框:
$('#identifier').modal(options)demo:
- $(function () {
- $("#btn_edit").click(function () {
- $("#myModal").modal("show");
- console.log("打开静态框");
- });
- })
遇到的问题:
用js的方式调用,打开modal静态框的时候一直包下面的错误,
Infographic.js:176 Uncaught TypeError: $(...).modal is not a function
at HTMLButtonElement.<anonymous> (Infographic.js:176)
at HTMLButtonElement.dispatch (jquery.min.js:3)
at HTMLButtonElement.r.handle (jquery.min.js:3)
解决方案:上面的问题主要是包的引入问题,要确保上面的包多已经引入,我就是在引入jquery包时,引入了2个重复的包,去掉其中的一个,问题解决了。