无法导航回以前的Bootstrap模式

时间:2016-05-20 09:48:53

标签: bootstrap-modal

我有两个Bootstrap模态。从第二个模态返回到上一个模态时,它是不可见的。第二个模态有一个文件字段。在更改文件字段的值时,第二个模态应隐藏,并应显示第一个模态。谁能帮我吗?以下是我的尝试:

<html lang="en">
<body>
<div class="container">
  <h2>Modal Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal123" data-dismiss="modal">Open Modal</button>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>

  <!-- Modal -->
  <div class="modal fade" id="myModal123" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.123</p>
<form action="demo_form.asp">
  Select a file: <input type="file" name="img" id="File">
</form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>
<script>
$("#File").change(function(){
   $("#myModal123").hide();
   $("#myModal").show();
   alert("Hello");
})
</script>
</body>
</html>

提前谢谢。

1 个答案:

答案 0 :(得分:0)

请将您的JQuery代码替换为

$("#File").change(function () {
            $("#myModal123").modal("hide");
            $("#myModal").modal("show");

        })