我有一个使用php
创建的列表while($row = $result->fetch_assoc()){ //$row is a row fetched from my database
<tr>
<td><?php echo $row['id']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['surname']?></td>
<td><a href="#Modal" <?php echo "id= " . $row['username'] ?> class="btn btn-small btn-info" data-toggle="modal" > Vedi</a></td>
</tr>
}
模态是这样的:
<div id="Modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-header">
<a class="close" data-dismiss="modal" aria-hidden="true">×</a>
<h3 id="myModalLabel">user information</h3>
</div>
<div class="modal-body" id="loadInfo">
<div class="row-fluid">
<div class="span12">
<!-- my php code here -->
</div>
</div>
</div>
</div>
我的PHP代码必须引用一个精确的用户。所以我需要Modal可以接收它的id以执行正确的php代码。
如何获得此结果?
答案 0 :(得分:1)
将用户信息的值分配给javascript变量。将数据属性添加到模态切换按钮(如data-user_id=<?php echo $row['id']; ?>
)并创建一个jquery单击处理程序以更新模式的内容以匹配您单击的按钮。