我正在创建一个web页面,用于读取和显示网站内某个目录中的文件,我使用for-each循环遍历这些文件,并根据增量给出具体的名称。当用户单击特定的按钮时,我不希望我的表单传递特定的增量,这样我就知道当它转到下一个页面时使用哪个文件。按钮按预期显示增量,但是url总是传递"1“作为值,我真的不知道为什么,我附上了一张显示按钮工作的图片。
但是链接总是变成http://Mywebsite.com/AuthorizeCapabilityRequest.php?1
<?php
$images = glob($directory . "*.*");
echo "<div class='col-md-12' align='center'><div class='col-md-10'>
<table class='table table-bordered table-striped'>
<tr>
<th width='65%'>Filename</th>
<th width='20%'>Edit</th>
<th width='15%'>Refer</th>
</tr>";
$dir = "Capability_Request/*";
$zed = 1;
foreach(glob($dir) as $file)
{
$base = basename($file);
echo "<tr><td>";
if(!is_dir($file)) { echo basename($file);}
echo "</td><td><button type='button' class='btn btn-primary btn-
small' data-toggle='modal' data-target='#exampleModal$zed'>
$zed
</button> </td><td>
<!-- Button trigger modal -->
<button type='button' class='btn btn-primary' data-toggle='modal'
data-target='#exampleModalCenter'>
$zed
</button>
<!-- Modal -->
<div class='modal fade' id='exampleModalCenter' tabindex='-1'
role='dialog' aria-labelledby='exampleModalCenterTitle' aria-
hidden='true'>
<div class='modal-dialog modal-dialog-centered' role='document'>
<div class='modal-content'>
<div class='modal-header'>
<h5 class='modal-title' id='exampleModalLongTitle'>Refer
Capability to UNF</h5>
<button type='button' class='close' data-dismiss='modal'
aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>
<div class='modal-body'>";
$url = "AuthorizeCapabilityRequest.php?".$zed;
echo "<form action='$url' method='post'>";
echo "<h6>If you would like to refer the capability to the
UNF, and accept the capability request, select this
button:</h6>";
echo "<input class='btn btn-success btn-block' type='submit'
value='Submit'>";
echo "<hr>";
echo "<h6>If you would like to refer the capability to the
UNF, but deny the capability request, select this
button:</h6>";
echo "<button type='button' class='btn btn-warning btn-
block'>Refer</button>";
echo "<hr>";
echo "<h6>If you would like to deny the capability referral
to the UNF, select this button:</h6>";
echo "<button type='button' class='btn btn-danger btn-
block'>Deny</button>";
echo "<div class='modal-footer'>";
echo "<button type='button' class='btn btn-secondary' data-
dismiss='modal'>Cancel</button>";
echo "</form>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</td></tr>";
$zed++;
}
echo "</table></div></div>";
发布于 2018-07-17 03:36:54
元素的ID必须是唯一的。中的每次迭代都给'modal div‘相同的ID。
<div class='modal fade' id='exampleModalCenter' tabindex='-1'
role='dialog' aria-labelledby='exampleModalCenterTitle' aria-hidden='true'>
因此,您应该做几件事:确保ID都是惟一的(使用$zed
变量),然后让data-target
对应于这个惟一的ID(同样使用$zed
变量)。
编辑:这是一个如何工作的示例:
<button type="button" data-toggle="modal" data-target="#exampleModal<?php echo $zed; ?>">
your button
</button>
<div class="modal" id="exampleModal<?php echo $zed; ?>">
your modal
</div>
https://stackoverflow.com/questions/51368816
复制相似问题