简体   繁体   English

无法使用JavaScript关闭模式窗口

[英]Unable to close a modal window with javascript

I have a modal window for deletion confirmation. 我有一个用于删除确认的模式窗口。 Somehow I can't close this modal window. 我无法以某种方式关闭此模式窗口。 The following is how I coded. 以下是我的编码方式。 Does anyone have a clue what I did wrong? 有人知道我做错了什么吗?

 $('#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> 

I'm pretty sure the cancel button's click event has been fired as the other modal window (AddPkgItm) is shown after the button is clicked. 我很确定取消按钮的单击事件已经触发,因为单击该按钮后将显示另一个模式窗口(AddPkgItm)。 Just the confirmation does not go away. 只是确认不会消失。

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

should do it. 应该这样做。 See this plunker 看到这个矮人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM