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'>&times;</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));

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...