• 主页
  • 如何根据按钮单击更改Bootstrap模式内容

如何根据按钮单击更改Bootstrap模式内容

我需要能够改变一个模式内的内容取决于被点击的按钮。

例如,如果一个按钮被点击,它将只显示带有class ' one‘的div,而其他按钮将保持隐藏状态。

?

$('#exampleModalCenter').modal('toggle')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" class="btn" data-toggle="modal" data-target="#exampleModalCenter">one</button>

<button type="button" class="btn" data-toggle="modal" data-target="#exampleModalCenter">two</button>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

<!-- jQuery library -->


<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>


<button type="button" class="btn" data-toggle="modal" data-target="#exampleModalCenter">three</button>

<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <div class="one">Button one content</div>
        <div class="two">Button two content</div>
        <div class="one">Button three content</div>
      </div>
    </div>
  </div>
</div>

?

转载请注明出处:http://www.jxbyjx.net/article/20230508/1702059.html