将数据传递给引导模式 - 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章