0

我现在正面临 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:

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

4

1 回答 1

0

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

于 2017-06-25T18:01:00.403 回答