我用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>
}
Modal是这样的:
<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代码。
如何得到这个结果?
将用户信息的值赋给javascript变量。为模态切换按钮(如data-user_id=<?php echo $row['id']; ?>
)添加一个data属性,并创建一个jquery click处理程序来更新模态的内容,以匹配您单击的按钮。