无法使用javascript关闭模态窗口

时间:2016-03-22 01:13:35

标签: javascript bootstrap-modal

我有一个用于删除确认的模态窗口。不知怎的,我无法关闭这个模态窗口。以下是我编码的方式。有没有人知道我做错了什么?



$('#delpkgdtlPrompt').on('show.bs.modal', function(event) {
  $('#AddPkgItm').modal('hide');
  var button = $(event.relatedTarget); // Button that triggered the modal
  var pkgid = button.data('pkgid');
  var pkgdtldesc = button.data('pkgdtldesc');

  var dataString = 'pkgid=' + pkgid;
  alert(dataString);
  var modal = $(this);
})

$(document).on("click", ".btncancel", function(e) {
  e.preventDefault()
  $('#delpkgdtlPrompt').modal('hide');
  $('#AddPkgItm').modal('show');
});

<div class="modal fade" id="delpkgdtlPrompt" tabindex="-1" role="dialog" aria-labelledby="delpkgdtlPromptLabel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
        </button>
        <h2 class="modal-title text-center" id="delpkgdtlPromptLabel">Delete confirmation</h2>
      </div>
      <form action="" method="post" enctype="multipart/form-data" class="form-horizontal" id="frmdelpkgdtl">
        <div class="modal-body">
          <div id="pkgdtldesc" name="pkgdtldesc">
            <p>You are about to delete the record</p>
          </div>
        </div>
        <div class="modal-footer">
          <div class="col-sm-offset-3 col-sm-9">
            <button name="btncancel" id="btncancel" type="submit" class="btncancel btn btn-default"><i class="fa fa-undo"></i>&nbsp;Cancel</button>
            <button name="btndelpkgdtl" id="btndelpkgdtl" type="submit" class="clsdelpkgdtl btn btn-warning"><i class="fa fa-trash"></i>&nbsp;Delete</button>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

我非常确定取消按钮的点击事件已被触发,因为在单击按钮后会显示另一个模态窗口(AddPkgItm)。只是确认不会消失。

1 个答案:

答案 0 :(得分:0)

$('#delpkgdtlPrompt').modal('hide'); 

应该这样做。见plunker