【发布时间】:2012-12-12 07:15:34
【问题描述】:
我希望能够通过 Bootstrap 的模态插件使页面上的多个不同链接重用一个模态 div:
<h3>This button shows a modal (<code>#utility</code>) with text "Phasellus <em>tincidunt gravida</em>..."</h3>
<br />
<a id="file_attach" data-toggle="modal" href="http://fiddle.jshell.net/jhfrench/6K8rD/show/" data-target="#utility" class="btn">Modal 1</a><br />
<h3>This button should invoke the same modal (<code>#utility</code>), but fill it with text "Phasellus <em>egestas est eu</em>..."</h3>
<br />
<a id="file_attach" data-toggle="modal" href="http://fiddle.jshell.net/jhfrench/AWSnt/show/" data-target="#utility" class="btn">Modal 2</a><br />
<!-- Modal -->
<div id="utility" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Click outside modal to close it</h3>
</div>
<div class="modal-body">
<p>One fine body…this is getting replaced with content that comes from passed-in href</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
我希望单击任一链接(样式为按钮)将调用模态并加载与单击的按钮对应的页面(值为href)的模态。相反,模式总是加载您首先单击的链接的内容;模态不会“刷新”应由“其他”链接的href 指定的内容。
我认为这是一个 Bootstrap 错误,但我在这里提出问题以防我使用不正确。
请参阅http://jsfiddle.net/jhfrench/qv5u5/ 进行演示。
【问题讨论】:
-
你试过调用removeData函数吗?类似于: $('body').on('hidden', '.modal', function () { $(this).removeData('modal'); });
-
@Scott:试过了(见小提琴),但没有乐趣。
标签: jquery twitter-bootstrap modal-dialog