基于modalphp的动态数据目标
我循环一个动态PHP值和一个与模态表单链接的按钮 问题是,我目前正在将数据目标设置为循环的一个动态值,但它从未起作用 这是循环的PHP+HTML代码:基于modalphp的动态数据目标,php,twitter-bootstrap,bootstrap-modal,Php,Twitter Bootstrap,Bootstrap Modal,我循环一个动态PHP值和一个与模态表单链接的按钮 问题是,我目前正在将数据目标设置为循环的一个动态值,但它从未起作用 这是循环的PHP+HTML代码: while($row = mysqli_fetch_assoc($seleccionar_requerimientos)){ $req_id = $row['req_id']; ?> <tr&g
while($row = mysqli_fetch_assoc($seleccionar_requerimientos)){
$req_id = $row['req_id'];
?>
<tr>
<td><?php echo "{$req_id}" ?></td>
<!-- Here we place the data-target to dynamic value -->
<td><p data-placement="top" data-toggle="tooltip" title="Editar"><button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" **data-target="#<?php echo $req_id; ?>" ><span class="fas fa-edit"></span></button></p></td>
<!-- Here we set the dynamic ID linked to previous trigger -->
<div class="modal fade" id="<?php echo $req_id; ?>" tabindex="-1" role="dialog" aria-labelledby="edit" 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"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
<h4 class="modal-title custom_align" id="Heading">Editar Requerimiento</h4>
</div>
<div class="modal-body">
<div class="form-group">
<textarea rows="2" class="form-control" placeholder="<?php echo $req_desc_corta; ?>"></textarea>
</div>
</div>
<div class="modal-footer ">
<button type="button" class="btn btn-warning btn-lg" style="width: 100%;"><span class="fas fa-wrench"></span> Actualizar</button>
</div>
</div>
</div>
</div>
<?php } ?>
我也会改变
<div class="modal fade" id="<?php echo $req_id; ?>" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
我认为在id
属性中只使用数字是个坏主意。请在数字前使用一些字符串。发件人:
必须至少包含一个字符
您的代码是否可能为$req\u id生成重复的值?
如果代码在您手动将ID放置到位时起作用,那么问题很可能是ID,并且没有很多错误的方式。要么存在重复的ID,要么它们的输出方式存在其他问题。你能添加整个页面的源代码吗?您的控制台是否警告您重复ID?那么在源代码中,它设置正确,那么问题出在哪里?我假设模态没有加载?你试过加载其他情态动词吗,它们有用吗?您是否正确地包含了引导javascript?您好,FrankerZ,非常感谢您的写作。问题是,它在源代码上看起来不错,但当单击时就不起作用了。如果数据目标和id都是动态值,那么它们在suorce代码中看起来不错,但不起作用。另一方面,如果我手动在它们上写下一个数字,那么模式工作得很好(但不是动态的,所以每个循环触发器打开相同的模式,这就是显示动态值的原因)。动态或静态并不会真正改变任何东西。如果它们在源代码中(您已经检查了数据目标和实际的模式id,并且看到在这两个位置实现了正确的id号,那么您不应该有问题)。编辑您的问题,并发布您的输出(此页面呈现后的HTML源代码)。@GuillermoFernándezRuiz您是否处理多个$req_id
s?如果是的话,你知道你在循环中只分配了其中一个吗?再次感谢FrankerZ,我也是这么想的。我已经写下了主要问题的HTML输出
data-target="#<?php echo $req_id; ?>"
data-target="#9"
<div class="modal fade" id="<?php echo $req_id; ?>" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
<div class="modal fade" id="9" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">