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

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


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值