我有一个小问题,我必须在 24 种不同的情况下使用模态,在进入模态之前我必须获取一个 id,以使用模态 id 测试此 id 并在模态中显示结果。不知道我表达得好不好!但这是代码
<!-- Modal -->
<?php
$x=7;
$case = $fun -> getCaseByIde($x);
?>
<div id="myModal-<?php echo $x; ?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content" style="text-align: center;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h1><?php echo $x; $case['titre']; ?></h1>
</div>
</div>
</div>
</div>
<!-- #END# Modal -->
<!-- Modal -->
<?php
$x=8;
$case = $fun -> getCaseByIde($x);
?>
<div id="myModal-<?php echo $x; ?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content" style="text-align: center;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h1><?php echo $x; $case['titre']; ?></h1>
</div>
</div>
</div>
</div>
<!-- #END# Modal -->
<!-- Modal -->
<?php
$x=9;
$case = $fun -> getCaseByIde($x);
?>
<div id="myModal-<?php echo $x; ?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content" style="text-align: center;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h1><?php echo $x; $case['titre']; ?></h1>
</div>
</div>
</div>
</div>
<!-- #END# Modal -->
您似乎正在手动创建所有 24 种模态?
尝试使用 for 循环:
<?php
$modalCount = 24; // Number of modals you want to create. (Nombre de modals à créer)
// Create a modal from 0 to 23. (Créer un modal de 0 à 23)
// Use "$x = 1" and "$x <= $modalCount" if you want from 1 to 24. (Utilise ... si tu veux de 1 à 24)
for ($x = 0 ; $x < $modalCount ; $x++): ?>
<!-- Modal -->
<?php $case = $fun->getCaseByIde($x); ?>
<div id="myModal-<?php echo $x; ?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content" style="text-align: center;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h1><?php echo $x; $case['titre']; ?></h1>
</div>
</div>
</div>
</div>
<!-- #END# Modal -->
<?php endfor; ?>
如果这不是您的问题,请更准确。