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
(我按照这个例子: 如何将值参数传递给Bootstrap中的modal.show()函数)
(and I also tried this: How to set the input value in a modal dialogue? )
((我也试过这个: 如何在模态对话框中设置输入值? ))
ask by Leon Cullens translate from so