我有一个从数据库创建列表的php代码。我从数据库中检索到的项目之一是行ID。我用以下代码创建列表:
<th>Cover Name</th>
<th>Sum Insured</th>
<th>Info</th>
<th style="width: 3.5em;"></th>
</tr>
</thead>
<tbody>
<?php while($row = mysql_fetch_array($query_set)) { ?>
<tr>
<td><?php echo $row['cover_name'] ?></td>
<td><?php echo 'R '.$row['sum_insured'] ?></td>
<td><?php echo $row['info'] ?></td>
<td>
<a href="cover-type.php?id=<?php echo $row['coverid']?>"><i class="fa fa-pencil"></i></a>
<a href="#myModal" onclick="<?php $coverid = $row['coverid'] ?>" role="button" data-toggle="modal"><i class="fa fa-trash-o"></i></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
调用
#myModal
的语法<a href="#myModal" onclick="<?php $coverid = $row['coverid'] ?>" role="button" data-toggle="modal"><i class="fa fa-trash-o"></i></a>
如您所见, anchor
#myModal
和onclick
单击 anchor 后,我想将
$coverid
传递给以下myModal弹出窗口 <div class="modal small fade" id="myModal" 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>
<h3 id="myModalLabel">Delete Confirmation</h3>
</div>
<div class="modal-body">
<p class="error-text"><i class="fa fa-warning modal-icon"></i>Are you sure you want to delete the cover?<br>This cannot be undone.</p>
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
<a href="delete-cover.php?id=<?php echo $coverid ?>" class="btn btn-danger" >Delete</a>
</div>
</div>
</div>
</div>
我觉得我需要某种形式的隐藏javascript变量
<a href="#myModal" onclick="<?php $coverid = $row['coverid'] ?>" role="button" data-toggle="modal"><i class="fa fa-trash-o"></i></a> and pass it to myModal window, but how do I do that ?
最佳答案
data-id="< ?php $coverid = $row['coverid'] ?>"
class="trash"
id="modalDelete"
在JQ中:
// on clik trash icon
$('.trash').click(function(){
//get cover id
var id=$(this).data('id');
//set href for cancel button
$('#modallCancel').attr('href','delete-cover.php?id='+id);
})
http://jsfiddle.net/4j59z60e/4/