簡體   English   中英

Twitter Bootstrap-將唯一的ID傳遞給模態

[英]Twitter Bootstrap - Passing a unique ID to a Modal

我進行了很多搜索,但在將唯一ID傳遞給值然后使用該ID進行PHP MySQL查詢以獲取圖書信息時仍然遇到一些麻煩。

我目前正在將唯一ID傳遞給模式,並通過輸入類型文本顯示它。 我只是很難弄清楚如何將id放入php變量中

這是我的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 );
    });

您需要回顯值:

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

使用此代替:

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

您可以通過javascript / coffee腳本執行類似的操作。

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

URL =唯一ID

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM