我有一个问题,我不能将任何参数传递给模态窗口(使用Bootstrap 3),我尝试使用此链接中说明的解决方案,但我无法使其工作:
Dynamically load information to Twitter Bootstrap modal
但是按下按钮,显示屏不会显示任何东西,显然是块,附上一张图片:
http://i.imgur.com/uzRUyf1.png
<div id="myModal" class="modal hide fade"> <div class="modal-header"> <button class="close" data-dismiss="modal">×</button> <h3>Title</h3> </div> <div class="modal-body"> <div id="modalContent" style="display:none;"> </div> </div> <div class="modal-footer"> <a href="#" class="btn btn-info" data-dismiss="modal" >Close</a> </div> </div>
JS代码:
$("a[data-toggle=modal]").click(function() { var essay_id = $(this).attr('id'); $.ajax({ cache: false,type: 'POST',url: 'backend.PHP',data: 'EID='+essay_id,success: function(data) { $('#myModal').show(); $('#modalContent').show().html(data); } }); });
按钮:
<a href='#myModal' data-toggle='modal' id='2'> Edit </a>
<?PHP $editId = $_POST['EID']; ?> <div class="jumbotron"> <div class="container"> <h1>The ID Selected is <?PHP echo $editId ?></h1> </div> </div>
解决方法
首先你应该修改模态HTML
structure.现在不正确,你不需要类.hide:
<div id="edit-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" 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">×</button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body edit-content"> ... </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
<a href="#myModal" data-toggle="modal" id="1" data-target="#edit-modal">Edit 1</a>
最后Js部分变得非常简单:
$('#edit-modal').on('show.bs.modal',function(e) { var $modal = $(this),esseyId = e.relatedTarget.id; $.ajax({ cache: false,data: 'EID=' + essayId,success: function(data) { $modal.find('.edit-content').html(data); } }); })
演示:@L_502_3@