將數據傳遞給引導模式 - Passing data to a bootstrap modal

問題:

I've got a couple of hyperlinks that each have an ID attached.我有幾個超鏈接,每個超鏈接都附有一個 ID。 When I click on this link, I want to open a modal ( http://twitter.github.com/bootstrap/javascript.html#modals ), and pass this ID to the modal.當我點擊這個鏈接時,我想打開一個模態( http://twitter.github.com/bootstrap/javascript.html#modals ),並將這個 ID 傳遞給模態。 I searched on google, but I couldn't find anything that could help me.我在谷歌上搜索,但找不到任何可以幫助我的東西。

This is the code:這是代碼:

<a data-toggle="modal" data-id="@book.Id" title="Add this item" class="open-AddBookDialog"></a>

Which should open:哪個應該打開:

<div class="modal hide" id="addBookDialog">
    <div class="modal-body">
        <input type="hidden" name="bookId" id="bookId" value=""/>
    </div>
</div>

With this piece of code:用這段代碼:

$(document).ready(function () {
    $(".open-AddBookDialog").click(function () {
        $('#bookId').val($(this).data('id'));
        $('#addBookDialog').modal('show');
    });
});

However, when I click the hyperlink, nothing happens.但是,當我單擊超鏈接時,沒有任何反應。 When I give the hyperlink <a href="#addBookDialog" ...> , the modal opens just fine, but it does't contain any data.當我提供超鏈接<a href="#addBookDialog" ...> ,模式打開得很好,但它不包含任何數據。

I followed this example: How to pass values arguments to modal.show() function in Bootstrap我按照這個例子: How to pass values arguments to modal.show() function in Bootstrap

(and I also tried this: How to set the input value in a modal dialogue? ) (我也試過這個: 如何在模態對話框中設置輸入值?


解決方案:

參考一: https://en.stackoom.com/question/iaXN
參考二: https://stackoom.com/question/iaXN
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章