如何解决HTML Modals没有弹出
我正在使用具有逻辑的PHP构建应用程序,
- 打开两个文件。
- 一个显示菜单的文件值,回显浏览器。
- 如果单击任何菜单,则需要打开一个模态,其值包含第二个文件。
我只是用while循环进行了迭代。 问题是... 来自第一个文件的菜单正在回显。但是,该模式仅适用于最后一个菜单。
当我检查时,将创建菜单和模态。 https://postimg.cc/crQ8JCr5-检查过的屏幕截图
$myfile1 = fopen("fisrt-file.dat","r") or die("Unable to open file!");
$myfile2 = fopen("Second-file.dat","r") or die("Unable to open file!");
while(!feof($myfile1)) {
$fistFile = fgets($myfile1);
$seconfFile = fgets($myfile2);
echo "<div class='one-by-three1'><div class='course-card1' data-toggle='modal' data-target='#".$seconfFile."'><p class='e-c-head'>".$fistFile."</p></div></div>";
echo "<div class='modal fade' id='".$seconfFile."' 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'>".$fistFile."</h5>
<button type='button' class='close' data-dismiss='modal' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</div>
<div class='modal-body'>
<p>Second file element</p>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-secondary' data-dismiss='modal'>Close</button>
</div>
</div>
</div>
</div>";
}
fclose($myfile1);
fclose($myfile2);
我使用了Bootstrap Modal。 菜单将数据目标作为第二个文件值传递。
解决方法
我看到您已更改为使用手风琴,但是正要告诉您它不起作用的原因,因此我会继续进行,以防它对其他人有所帮助。
原因是因为fgets读取行包括新行字符。因此,分配给模式的ID包含换行符,但最后一行在文件中没有换行,因此可以正常工作。
要使其正常工作,只需像下面这样限制行:
$fistFile = rtrim(fgets($myfile1));
$seconfFile = rtrim(fgets($myfile2));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。