Bootstrap Modal-静态框使用及遇到的问题

来源:互联网 发布:机械模拟仿真软件 编辑:程序博客网 时间:2024/06/06 18:58

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>
1.2:具体用法有2种
1、通过 data 属性:在控制器元素(比如按钮或者链接)上设置属性 data-toggle="modal",同时设置 data-target="#identifier" 或 href="#identifier" 来指定要切换的特定的模态框(带有 id="identifier")。

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个重复的包,去掉其中的一个,问题解决了。


阅读全文
1 0