dtzh131555 2014-10-07 19:47
浏览 45

将变量传递给jquery

My goal is to open the details of a link in the loop $viewhh with an ID in a modal. I have tried so many different ways through jquery, etc and have not been able to get anything to work. Just calling the page works fine, but trying to load in a modal has been futile for me.

<div class="row">
             <div class="col-md-12">
                <p><a class="btn btn-default" href="add_praise.php" role="button">Add a Praise</a></p>
                <h2>Praises</h2>
                <p><?php
                    $query = "SELECT praise.id, praise.title, praise.description, praise.created, member.username FROM praise INNER JOIN member ON praise.member_id=member.id ORDER BY praise.created desc;";
                    $stmt = $db->query($query);
                    printf('<table class="table">');
                    printf('<thead><tr><th>Title</th><th>Posted By</th><th>Posted</th></tr></thead>');
                    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                        $created = date('m-d-Y', strtotime($row['created']));
                        $viewhh = '<a href="view_praise.php?id=' .
                                urlencode($row["id"]) . '">' . ($row["title"]) . '</a>';
                        printf("<tbody><tr><td> %s </td> <td> %s </td><td> %s </td><td> %s </td></tr></tbody>", $viewhh, htmlentities($row["username"]), $created, $viewbutton);
                        printf("</table");
                    }
                    ?>   </p>

            </div>

This is the page being called

<?php
$praiseid = urldecode($_GET['id']);
$sth = $db->prepare("select * from praise where id = '$praiseid'");
$sth->execute();
            $result = $sth->fetch(PDO::FETCH_ASSOC);
            $title = $result['title'];
                    $description= $result['description'];


            ?>  
<div class="container">
    <!-- Example row of columns -->
    <div class="row">
        <div class="col-md-4">

            <h2><?php echo $title;  ?></h2>
            <div><?php echo $description;  ?></div>

        </div>
</div>

I have tried adding this but only get the first record now.

<script>
         $(function () { 

            $("#loadpraise").colorbox({ iframe: true, width: "90%", height: "90%", closeButton: false });

            $("#events").colorbox({
                onOpen: function () { alert("Colorbox onOpen"); },
                onLoad: function () { alert("Colorbox onLoad"); },
                onComplete: function () { alert("Colorbox onComplete"); },
                onCleanup: function () { alert("Colorbox onCleanup"); },
                onClosed: function () { alert("Colorbox onClosed"); }
            });

            $("#childForm").colorbox({ closeButton: false, onClosed: function () { alert($.colorbox.popupResult) } });
        });
     </script>
  • 写回答

1条回答 默认 最新

  • duai0935 2014-10-08 22:47
    关注

    I got it working using BootStrap 3 modal.

    The link calling the record: just added data-toggle="modal" and data-target="#myModal"

    $viewpraise = '<a data-toggle="modal" href="view_praise.php?id=' . urlencode($row["id"]) . '" data-target="#myModal">' . ($row["title"]) . '</a>';
    

    included the modal for remote call on the same page. The remote page is loaded into the "modal-content" div.

    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
            </div> <!-- /.modal-content -->
        </div> <!-- /.modal-dialog -->
    </div> <!-- /.modal -->
    

    Then on the page called add the rest of the modal content:

    <!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title>Remote file for Bootstrap Modal</title>  
      <script>
    
       $('body').on('hidden.bs.modal', '.modal', function () {
            $(this).removeData('bs.modal');
          });</script>
    
    </head>
    <body>
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                     <h4 class="modal-title">Modal title</h4>
                </div>          <!-- /modal-header -->
                <div class="modal-body">
                 <h2><?php echo $title;  ?></h2>
                <div><?php echo $description;  ?></div>
                </div>          <!-- /modal-body -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <!--                <button type="button" class="btn btn-primary">Save changes</button>-->
                </div>          <!-- /modal-footer -->
    </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥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不能升级的情况