从其他html文件打开Modal(bootstrap) [英] Open Modal (bootstrap) from other html-file

查看:235
本文介绍了从其他html文件打开Modal(bootstrap)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 bootstrap 构建网站。但我有点死路一条。我已经从给定的例子中创建了一个模态(见下文)。正如您可能看到的,这是从他们的网站直接采取的模式。

I'm building a website using bootstrap. But i'm come to somewhat of an dead-end. i've created a modal from an given example (see below). As you might see, this is a modal taken straight from their website.

<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">&times;</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>

我使用按钮打开此对话框。

I open this dialog using a button.

<button type="button" class="btn btn-default btn-sm" data-toggle="modal" data-target="#myModal" >

但我想保持我的模态单独 aspx / html-files 。如何将这些模态保存在不同的 html / aspx - 文件中?

But i want to keep my modals in seperate aspx/html-files. How can i open these modals when they are kept inside different html/aspx - files ?

示例:
如果按钮位于 index.Html 内,但模态位于 newTaskModal.html ,我怎么打开模态? (如果两者都在index.html内,则没有问题)

example: if the button is inside index.Html but the modal is inside newTaskModal.html, how would i open the modal? (If both are inside index.html, then there are no problems)

注意:我不能/不能使用HTML5(公司标准)

Note: I don't/can't use HTML5 (company-standards)

推荐答案

如果您使用的是jquery,可以使用ajax调用下载页面:

if you're using jquery, you could download the page using an ajax call:

$.ajax({
  url: 'newTaskModal.html',
  dataType: 'text',
  success: function(data) {
    alert(data);
    // todo:  add the html to the dom...
  }
});

如果您正在构建单页应用程序,您可能需要查看旨在解决此问题的框架问题类型:
durandal

If you're building a single page application you might want to check out a framework designed to solve this type of problem: durandal

这篇关于从其他html文件打开Modal(bootstrap)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆