douliu1092 2013-09-20 03:20
浏览 42
已采纳

Bootstrap popover不在while循环中工作

I'm trying to use the popover element from bootstrap's framework for Javascript/jQuery and it only works with the first one in the while loop. How can I make it work for all of them?

Why is this? Been trying to figure this out for a bit...

<?php
require 'include.php';
session_start();

    $selectBets = $dbc->query("SELECT * FROM `bets` ORDER BY `bid` DESC LIMIT 10");
?>
<style type="text/css">
#hash_text {
    font-size: 3.8px;
}
</style>
<table class="table table-striped table-bordered table-hover">
                <thead>
                  <tr>
                    <th>Bet Number</th>
                    <th>Amount</th>
                    <th>Send Address</th>
                    <th>Time Created</th>
                    <th>Time Expires</th>
                    <th>Chance to Win</th>
                    <th>Payout Multiplier</th>
                    <th>Final Profit</th>
                    <th>Server Hash</th>
                  </tr>
                </thead>
                <tbody>
                <?php while($BetsArray = $selectBets->fetch()) { ?>
                  <tr>
                  <td><?php echo $BetsArray['bid']; ?></td> 
                  <td><?php echo $BetsArray['amount']; ?></td> 
                  <td><?php echo $BetsArray['deposit_address']; ?></td> 
                  <td><?php echo date('m/d/Y - H:i:s', $BetsArray['time_created']); ?></td> 
                  <td><?php echo date('m/d/Y - H:i:s', $BetsArray['time_expires']); ?></td> 
                  <td><?php echo $BetsArray['win_chance']; ?></td> 
                  <td><?php echo $BetsArray['multiplier']; ?></td> 
                  <td><?php echo $BetsArray['profit']; ?></td> 
                  <td><a id="hash" data-container="body" data-toggle="popover" data-placement="right">Click here for Server Hash</a></td>
                  </tr>
                <?php } ?>
                </tbody>
              </table>
              <script type="text/javascript">
              $(function() {
                $('#hash').popover({
                    html: true,
                    placement: 'right',
                    content: '<?php echo '<span id="hash_text">' . hash('sha512', $BetsArray['number'] . '-' . $_SESSION['client_seed']) . '</span>'; ?>'
                });
              });
              </script>
  • 写回答

1条回答 默认 最新

  • donglu9134 2013-09-20 03:24
    关注

    You are creating the popover element by duplicating the ids. Change it to class and see it working.

    <a id="hash" data-container="body" data-toggle="popover" data-placement="right">Click here for Server Hash</a>
    

    When you bind to the popover using the id selector $('#hash') it will select only the first element with id that appears in DOM and hence the behavior that you are seeing.

    If you want to place a quick fix then you can use attribute selector to select the id like this.

    $('[id=hash]').popover({
                        html: true,
                        placement: 'right',
                        content: '<?php echo '<span id="hash_text">' . hash('sha512', $BetsArray['number'] . '-' . $_SESSION['client_seed']) . '</span>'; ?>'
    });
    

    But never ever do that

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况