問題:
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