【问题标题】:bootstrap-growl doesn't work inside a while loopbootstrap-growl 在 while 循环中不起作用
【发布时间】:2017-11-28 15:42:27
【问题描述】:

我现在正面临 bootstrap-growl 插件问题显示,当我将两个按钮(它们触发通知)放在循环之外时,我可以清楚地看到我的两个通知,一切都按预期进行。所以从技术上讲,这个插件和循环之间存在一定的冲突。你有没有遇到过这个问题,即使两个按钮都在循环内,我怎么能得到我的通知?提前感谢您的帮助:)

这是我使用插件的部分:

<?php
$meinKommentare = controller_alleKommentareLesen();
if ($meinKommentare->rowCount() > 0) {
    while ($row = $meinKommentare->fetch(PDO::FETCH_ASSOC)) {
        extract($row);
?>
        <tr>
            <td><?php echo $kommentarDatum; ?></td>
            <td><?php echo $benutzerName; ?></td>
            <td></td>
            <td><?php echo $kommentarInhalt; ?></td>
            <td style="text-align: center">
                <button id="bestaetigungButton" class="btn btn-success btn-xs" onclick="kommentarBestaetigen();"> <i class="fa fa-check fa-2x" ></i></button>
                <button id="loeschungButton" class="btn btn-danger btn-xs" onclick="kommentarLoeschen();"> <i class="fa fa-trash-o fa-2x "></i></button>
            </td>
        </tr>
<?php
    }
}
?>

这是我的 Javascript 代码:

<script>
        $("#bestaetigungButton").click(function () {
            $.bootstrapGrowl("another message, yay!", {
                ele: 'body', // which element to append to
                type: 'info', // (null, 'info', 'error', 'success')
                offset: {from: 'top', amount: 20}, // 'top', or 'bottom'
                align: 'right', // ('left', 'right', or 'center')
                width: 250, // (integer, or 'auto')
                delay: 4000,
                allow_dismiss: true,
                stackup_spacing: 10 // spacing between consecutively stacked growls.
            });
        });
    </script>

PS:

当我在循环之外使用两个按钮时,我没有做任何改变 在我的代码中

【问题讨论】:

  • 您的 php 正在生成 html。我们需要查看它生成的 html。查看浏览器中页面的 html 源代码with while 循环,然后without while 循环。在这两种情况下都发布相关部分的 html 源代码。
  • extract($row); 非常糟糕的做法,特别是在全球范围内。

标签: javascript php css twitter-bootstrap bootstrap-notify


【解决方案1】:

您在循环中放置了一个带有id="bestaetigungButton" 的按钮。这样您将拥有许多具有相同id="bestaetigungButton" 的按钮。 我认为当您单击时,它将与唯一的第一个一起使用。 我建议你应该使用class="bestaetigungButton"而不是id,并将js文件更改为:$(".bestaetigungButton").click

【讨论】:

  • 没错!非常感谢您的帮助,我很感激:)。事实上,即使是第一行也无法使用 id,但现在一切正常。我怎么能错过这样的事情?很明显,一个 id 同时针对一个精确元素和一个类许多元素。再次感谢 ThucVu
猜你喜欢
  • 1970-01-01
  • 2013-07-31
  • 2011-10-19
  • 1970-01-01
  • 2015-08-02
  • 2017-11-13
  • 1970-01-01
  • 1970-01-01
  • 2018-06-12
相关资源
最近更新 更多