将参数发送到引导模式窗口?

我有一个问题,我无法将任何参数传递给模式窗口(使用 Bootstrap 3),我尝试使用此链接中所述的解决方案,但无法使其工作:

I have a problem, I cannot pass any parameters to a modal window (using Bootstrap 3), I tried using the solution stated in this link, but I cannot make it work:

将信息动态加载到 Twitter Bootstrap 模式

(解决方案kexxcream用户).

(Solution kexxcream user).

但是按下按钮,显示屏什么也没有显示,显然是块,附下一张图片:

But pressing the button, the display does not show me anything, apparently blocks, attached a picture below:

http://i.imgur.com/uzRUyf1.png

我已附上代码(左上方相同的代码帖子);

I have attached the code (same code post above left);

HTML 代码:

      <div id="myModal" class="modal hide fade">
      <div class="modal-header">
        <button class="close" data-dismiss="modal">&times;</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 代码(backend.php):

PHP Code (backend.php):

<?php
$editId = $_POST['EID'];
?>
  <div class="jumbotron">
   <div class="container">
    <h1>The ID Selected is <?php echo $editId ?></h1>
   </div>
  </div>

推荐答案

首先你应该修复模态 HTML 结构.现在不正确了,你不需要类 .hide:

First of all you should fix modal HTML structure. Now it's not correct, you don't need class .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">&times;</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>

然后链接应该通过 data-target 属性指向这个模态:

Then links should point to this modal via data-target attribute:

<a href="#myModal" data-toggle="modal" id="1" data-target="#edit-modal">Edit 1</a>

终于Js部分变得很简单了:

Finally Js part becomes very simple:

    $('#edit-modal').on('show.bs.modal', function(e) {

        var $modal = $(this),
            esseyId = e.relatedTarget.id;

        $.ajax({
            cache: false,
            type: 'POST',
            url: 'backend.php',
            data: 'EID=' + essayId,
            success: function(data) {
                $modal.find('.edit-content').html(data);
            }
        });
    })

相关文章