最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to close the modal popup? - Stack Overflow

matteradmin5PV0评论

this is my bootstrap modal code

  <form class="form-horizontal" method="post" name="addform" id="formid">
    <div id="myModal" >
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
    <h3 id="myModalLabel">Add Question</h3>
    </div>
   <div class="modal-footer">
    <input type="button"  onClick="aj_add_question(<?=$id?>);" class="btn btn-primary" id="add_button" name="Add" value="Add Question">
   <button type="button" class="btn btn" data-dismiss="modal" aria-hidden="true">cancel</button>
    </div> 
    </div>

    <div class="modal-footer">
    <input type="button"  value="Add Page"  onclick="aj_add_page();" class="btn btn-primary" />
    <button type="button" class="btn btn" data-dismiss="modal" aria-hidden="true">cancel</button>
    </div>
 </form>

now onclick

Add Question

i have to close current popup

then i have written code

<script>
 $(document).ready(function(){
alert("Question Added..");
$('#formid').hide();
});
</script>

it will hide but get screen black

this is my bootstrap modal code

  <form class="form-horizontal" method="post" name="addform" id="formid">
    <div id="myModal" >
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
    <h3 id="myModalLabel">Add Question</h3>
    </div>
   <div class="modal-footer">
    <input type="button"  onClick="aj_add_question(<?=$id?>);" class="btn btn-primary" id="add_button" name="Add" value="Add Question">
   <button type="button" class="btn btn" data-dismiss="modal" aria-hidden="true">cancel</button>
    </div> 
    </div>

    <div class="modal-footer">
    <input type="button"  value="Add Page"  onclick="aj_add_page();" class="btn btn-primary" />
    <button type="button" class="btn btn" data-dismiss="modal" aria-hidden="true">cancel</button>
    </div>
 </form>

now onclick

Add Question

i have to close current popup

then i have written code

<script>
 $(document).ready(function(){
alert("Question Added..");
$('#formid').hide();
});
</script>

it will hide but get screen black

Share Improve this question edited Feb 7 at 7:30 DarkBee 15.5k8 gold badges72 silver badges118 bronze badges asked Oct 7, 2014 at 10:08 CoderbabaCoderbaba 131 gold badge1 silver badge5 bronze badges 4
  • Try close the modal as $('#myModal').modal('hide'); – Gowri Commented Oct 7, 2014 at 10:11
  • Try this: $("#modal").modal("hide"); – prava Commented Oct 7, 2014 at 10:12
  • updated my edit close the modal with model id not the form id $('#myModal').modal('hide'); – Gowri Commented Oct 7, 2014 at 10:19
  • Are oyu sure this problem is in any way related to PHP? What have you tried to resolve it? – Nico Haase Commented Jun 10, 2024 at 10:13
Add a ment  | 

1 Answer 1

Reset to default 1

I think you are not using modal popup syntax properly, can you try the following:

<div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="mymodaltitle" aria-hidden="true">
    <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
              **--- put your form here**
            </div>
            <div class="modal-footer">
            </div>
         </div>
     </div>
</div>

Then, as others have suggested use $("#mymodal").modal('hide')

Post a comment

comment list (0)

  1. No comments so far