隐藏的 div 在使用模态框的 for 循环中无法正常工作

发布于 2024-11-09 04:35:03 字数 3137 浏览 0 评论 0原文

我有一个 mysql select,它会在我在 for 循环中设置的

    中吐出所有结果。这很好用。但是,我希望在每个结果的底部有一个“单击更多”类型的链接,单击时会在模式框中打开。我也让这个工作得很好。然而,不起作用的是模式框中显示的数据。它正确显示数据,但无论您单击哪个结果,它都来自第一个结果。我以为我的 for 循环设置不正确,但是当我更改模态框内容所在的 div 的 id 时它会起作用(但模态框显然不起作用)。

是否有某种原因隐藏 div 会扰乱 for 循环直至显示哪一行?

的 for 循环,

        for($i=0; $i<$num_results; $i++)
        {
            $row = mysql_fetch_array($result);

        ?>
        <div id='basic-modal'>
            <ul style="background-color:#F5F5F5; padding:2px;">
                <li class="program" style="font-size:18px;"><strong><?php echo trim ($row["program"]); ?></strong></li>
                <li><strong>Sponsored by:</strong> <i><?php echo trim ($row["organization"]); ?></i></li>            
                <li><strong>Discipline:</strong> <?php echo trim ($row["discipline"]); ?></li>            
                <li><strong>Mission:</strong> <?php echo trim ($row["mission"]); ?></li>            
                <li><strong>Description:</strong> <?php echo trim ($row["content"]); ?></li>            
                <li><strong>Grade(s):</strong> <?php echo trim ($row["grade"]); ?></li>
                <li><strong>Cost:</strong> <?php echo trim ($row["cost"]); ?></li>
                <li>&nbsp;</li> 
                <li><a href="#" class="basic more">Contact Info</a></li>   


            </ul>
            <br />
            <br />
        </div>

        <!-- pop up contact info -->
        <div id="basic-modal-content">
            <ul style="font-size:12px">
                <li class="program" style="font-size:18px;"><strong><?php echo trim ($row["program"]); ?></strong></li>
                <li><strong>Sponsored by:</strong> <i><?php echo trim ($row["organization"]); ?></i></li>            
                <li><strong>Contact Person:</strong> <?php echo trim ($row["contact"]); ?></li>            
                <li><strong>Contact Email:</strong> <a href="mailto:<?php echo trim ($row["email"]); ?>"><?php echo trim ($row["email"]); ?></a></li>            
                <li><strong>Contact Phone:</strong> <?php echo trim ($row["phone"]); ?></li>            
                <li><strong>Contact Hours:</strong> <?php echo trim ($row["contactHours"]); ?></li>            
            </ul>
        </div>

        <!-- preload the images -->
        <div style='display:none'>
            <img src='images/x.png' alt='' />
        </div>            

        <?php
        }
        ?>

下面是我使用 Eric Martin 的 SimpleModal 如果这有什么不同的话。 感谢您的帮助。

I have a mysql select and it spits out all the results in a <ul> that I have setup in a for loop. This works great. However, I wanted to have a "click more" type link at the bottom of each result that opens in a modal box when clicked. I also got this working just fine. What doesn't work, however, is the data inside what is displayed inside the modal box. It displays the data correctly but it is from the first result no matter what result you click. I thought I just didn't have my for loop setup correctly but it works when I change the id of the div the content is in for the modal box (but then the modal box doesn't work obviously).

Is there some reason why hiding a div would mess a for loop up as far as which row to display?

Below is the for loop

        for($i=0; $i<$num_results; $i++)
        {
            $row = mysql_fetch_array($result);

        ?>
        <div id='basic-modal'>
            <ul style="background-color:#F5F5F5; padding:2px;">
                <li class="program" style="font-size:18px;"><strong><?php echo trim ($row["program"]); ?></strong></li>
                <li><strong>Sponsored by:</strong> <i><?php echo trim ($row["organization"]); ?></i></li>            
                <li><strong>Discipline:</strong> <?php echo trim ($row["discipline"]); ?></li>            
                <li><strong>Mission:</strong> <?php echo trim ($row["mission"]); ?></li>            
                <li><strong>Description:</strong> <?php echo trim ($row["content"]); ?></li>            
                <li><strong>Grade(s):</strong> <?php echo trim ($row["grade"]); ?></li>
                <li><strong>Cost:</strong> <?php echo trim ($row["cost"]); ?></li>
                <li> </li> 
                <li><a href="#" class="basic more">Contact Info</a></li>   


            </ul>
            <br />
            <br />
        </div>

        <!-- pop up contact info -->
        <div id="basic-modal-content">
            <ul style="font-size:12px">
                <li class="program" style="font-size:18px;"><strong><?php echo trim ($row["program"]); ?></strong></li>
                <li><strong>Sponsored by:</strong> <i><?php echo trim ($row["organization"]); ?></i></li>            
                <li><strong>Contact Person:</strong> <?php echo trim ($row["contact"]); ?></li>            
                <li><strong>Contact Email:</strong> <a href="mailto:<?php echo trim ($row["email"]); ?>"><?php echo trim ($row["email"]); ?></a></li>            
                <li><strong>Contact Phone:</strong> <?php echo trim ($row["phone"]); ?></li>            
                <li><strong>Contact Hours:</strong> <?php echo trim ($row["contactHours"]); ?></li>            
            </ul>
        </div>

        <!-- preload the images -->
        <div style='display:none'>
            <img src='images/x.png' alt='' />
        </div>            

        <?php
        }
        ?>

I'm using Eric Martin's SimpleModal if that makes a difference.
Thanks for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Hello爱情风 2024-11-16 04:35:03

你的每个div都有相同的id,这是错误的

You have same id of each div it is wrong

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文