新帖发布更新按钮

时间:2017-12-24 19:17:26

标签: javascript html css bootstrap-modal

<i class="fa fa-plus-square-o" aria-hidden="true" style="font-size: 45px; cursor: pointer;"></i>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

如何将此按钮变为模态?我一直在研究这个按钮,想要让用户可以点击并打开模态视图。

2 个答案:

答案 0 :(得分:1)

您在按钮上缺少数据切换数据目标属性:

data-toggle="modal" data-target="#myModal"
  • data-toggle描述您尝试切换的哪种类型的引导对象

其他数据切换示例包括:

data-toggle="modal"
data-toggle="collapse"
data-toggle="dropdown"
data-toggle="tab"
  • data-target定位您尝试切换的特定对象,在本例中为#myModal。

&#13;
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<i class="fa fa-plus-square-o" aria-hidden="true" style="font-size: 45px; cursor: pointer;" data-toggle="modal" data-target="#myModal"></i>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

按一下按钮

 <button type="button" id="update-btn" class="btn btn-primary">Update</button>

在你的模态课程之外然后在你的script标签

   $('#update-btn').click(function()({
     $('#myModal').modal('show');
});