bootstrap-growl在while循环中不起作用

问题描述 投票:0回答:1

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

当我在循环外面取两个按钮时,我的代码没有任何变化

javascript php css twitter-bootstrap bootstrap-notify
1个回答
0
投票

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

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