Bootstrap 模态和传递值

Bootstrap modal and passing value

当我点击编辑时,'id' 应该传递到自己的页面并且应该弹出模式。但它不起作用。请帮助我

PHP 和 Bootstrap

<tr>        
    <td><?php echo $row['name']; ?></td>   
    <td><a data-toggle="modal" data-target="#myModal" href='?id=<?php echo $row['id']; ?>'>Edit</a> </td>          
</tr>

模态

<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
         ------
         -----
         -----
    </div>
</div>

<a></a> 标签中创建 class Edit。使用此 class 调用模态。并且,添加 data-Id="<?echo $row['id'];?>"

<tr>        
    <td><?php echo $row['name']; ?></td>   
    <td>
        <a class='Edit' data-toggle="modal" href="#form_modal" data-target="#myModal" data-Id="<?php echo $row['id'];?>">Edit</a>
    </td>          
</tr>

将此代码放在 页脚

<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">

        </div>
    </div>
</div>

JS

<script>
$('.Edit').click(function(){
    var Id=$(this).attr('data-Id');
    $.ajax({url:"SomePage.php?Id="+Id,cache:false,success:function(result){
        $(".modal-content").html(result);
    }});
});
</script>

创建somepage.php(如果你想更改此页面名称。在<script></script>中也更改。两者都是相关的。)

SomePage.php

<?php
$Id=$_GET['Id'];
?>

<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>
    <h4 class="modal-title" id="fam_id"></h4>
</div>
<div class="modal-body">
    <?php echo $Id;?>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>

有关详细信息,请单击