我正在使用 bootstrap
构建网站。但我已经走到了死胡同。我从一个给定的例子中创建了一个模态(见下文)。如您所见,这是直接从他们的网站上获取的模式。
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Nieuwe Taak toevoegen</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
我使用一个按钮打开这个对话框。
<button type="button" class="btn btn-default btn-sm" data-toggle="modal" data-target="#myModal" >
但我想将模态框保存在单独的 aspx/html-files
中。当这些模式保存在不同的 html/aspx - 文件
中时,我如何打开它们?
示例:
如果按钮在 index.Html
内,但模态框在 newTaskModal.html
内,我该如何打开模态框? (如果都在index.html里面,那就没问题了)
注意:我不/不能使用 HTML5(公司标准)
最佳答案
如果您使用的是 jquery,则可以使用 ajax 调用下载页面:
$.ajax({
url: 'newTaskModal.html',
dataType: 'text',
success: function(data) {
alert(data);
// todo: add the html to the dom...
}
});
如果您正在构建单页应用程序,您可能需要查看旨在解决此类问题的框架: <强> durandal
关于javascript - 从其他 html 文件打开模态( Bootstrap ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23427371/