相同的模态不会在两个单独的文件中弹出

问题描述 投票:0回答:1
php bootstrap-4
1个回答
0
投票

您面临的问题可能是因为您在两个不同的文件中包含具有相同 ID 的相同模式。当两个文件都包含在同一页面上时,将会有两个具有相同 ID 的模式,这可能会导致问题。

一种解决方案可能是在包含

tabSurveyPending.php
tabCompleted.php
的父文件中仅包含一次模态。

如果您需要在两个文件中包含模态,因为它们是单独使用的,您可以考虑根据您在每个文件中设置的变量使模态的 ID 动态化。

这是一个例子:

在你的

workerSurveyModal.php

<div class="modal fade" id="<?php echo $modalId; ?>" tabindex="-1" role="dialog" aria-labelledby="<?php echo $modalId; ?>Label" aria-hidden="true">
    <!-- rest of your modal code -->
</div>

在你的

tabSurveyPending.php

<?php
    session_start();
    $modalId = 'workerSurveyDecisionModalPending';
    require ("workerSurveyModal.php");
?>

在你的

tabCompleted.php

<?php
    session_start();
    $modalId = 'workerSurveyDecisionModalCompleted';
    require ("workerSurveyModal.php");
?>

这样,模态的每次包含都会有一个唯一的 ID。确保更新触发模式的 JavaScript 代码以使用正确的 ID。

© www.soinside.com 2019 - 2024. All rights reserved.