Twitter Bootstrap - 将唯一ID传递给模态

时间:2013-05-05 21:08:26

标签: php mysql twitter-bootstrap

我搜索了很多,但仍然在将唯一ID传递给值时遇到问题,然后使用该ID进行PHP MySQL查询以获取图书信息。

我目前正在将唯一ID传递给Modal并通过输入类型文本显示它。我只是很难搞清楚如何将id放入php Variable

这是我的HTMl / PHP代码

                    echo '<a data-toggle="modal" data-id="' . $book_id .'" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">View Info</a>';?>

        <!-- Modal -->
                <div class="modal hide" id="addBookDialog">
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">×</button>
                        <h3>Book Info</h3>
                    </div>
                    <div class="modal-body">
                        <p>some content</p>
                        <?php 
                        echo $test = '<input type="text" name="bookId" id="bookId"/>';

                            $book_info = get_book_info($book_id);

                            while($row1 = mysqli_fetch_array($book_info))
                            {
                                $email = $row['email'];
                                echo "<p><strong>Title: </strong>" . $row1['title'] . "</p>";
                                echo "<p><strong>Author: </strong>" . $row1['author'] . "</p>";
                                echo "<p><strong>Edition: </strong>" . $row1['edition'] . "</p>";
                                echo "<p><strong>ISBN: </strong>" . $row1['isbn'] . "</p>";
                                echo "<p><strong>Price: </strong>" . $row1['price'] . "</p>";
                                echo "<p><strong>Seller's Name: </strong>" . $row1['name'] . "</p>";
                                echo "<p><strong>Seller's E-mail: </strong><a href='mailto:$email'>$email</a></p>";
                            }?>
                    </div>
                    <div class="modal-footer">
                        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
                    </div>
                </div>

这是我的jquery

        $(document).on("click", ".open-AddBookDialog", function () {
         var myBookId = $(this).data('id');
         $(".modal-body #bookId").val( myBookId );
    });

2 个答案:

答案 0 :(得分:1)

您需要回显价值:

data-id="<?php $book_id ?>"

请改用:

data-id="<?php echo $book_id; ?>"

答案 1 :(得分:0)

您可以通过javascript / coffee脚本执行此类操作。

($ "a[data-toggle=modal]").click ->
target = ($ @).attr('data-target')
url = ($ @).attr('href')
($ target).load(url)

网址=唯一身份证