1 <div id="myModal" class="modal hide fade"> 2 <div class="modal-header"> 3 <button type="button" class="close" data-dismiss="modal">x</button> 4 <h3>对话框标题</h3> 5 </div> 6 <div class="modal-body"> 7 <p>对话框主体</p> 8 </div> 9 <div class="modal-footer">10 <a href="#" class="btn" data-dismiss="modal">取消</a>11 <a href="#" class="btn btn-primary" data-dismiss="modal">确定</a>12 </div>13 </div>
The display effect is similar to the picture below:
You can directly call the modal dialog box using a button or link. This is a simple usage:
<button type="button" data-toggle="modal" data-target="#myModal">打开对话框</button><a href="#myModal" role="button" class="btn" data-toggle="modal">打开对话框</button>
<br/>
This can only display static content in the dialog box. Use the remote option of the dialog box to achieve a more powerful effect.
There are two methods, one is to use a link, the other is to use a script.
<a href="page.jsp" data-toggle="modal" data-target="#myModal">打开对话框</a>
When this link is clicked, the content of page.jsp will be loaded into the .modal-body of the dialog box , a dialog box appears.
$("#myModal").modal({ remote: "page.jsp" });
The effect of this script is the same as using a link. When this script is executed, page.jsp The content of will be loaded into the .modal-body of the dialog box, and the dialog box will be displayed.
Behind these two methods, Bootstrap calls jQuery's load() method to load the page.jsp page from the server. But this loading will only happen once. No matter how many times you click the link, or execute the script several times, or even change the value passed to the remote option, the dialog box will not reload the page. This is really a headache. But the problem can still be solved.
After searching and consulting relevant documents, I found that writing a message in the hidden event of the dialog box The statement is enough:
$("#myModal").on("hidden", function() { $(this).removeData("modal"); });
You can also remove the data before opening the dialog box each time, and the effect is the same.
Note: The above code is based on Bootstrap v2. If you use Bootstrap v3, the HTML of the modal dialog box and the way of writing the event are somewhat different. For example, for the above hidden event, it should be written as:
$("#myModal").on("hidden.bs.modal", function() { $(this).removeData("bs.modal"); });
The above is the detailed content of Solve the problem of Bootstrap only loading remote data once. For more information, please follow other related articles on the PHP Chinese website!