【问题标题】:Twitter Bootstrap modal - load "remote" contentTwitter Bootstrap modal - 加载“远程”内容
【发布时间】:2013-01-12 06:35:22
【问题描述】:

我正在尝试加载“远程”内容,基本上是通过 HTTP 请求(在同一站点上)发送的信息。返回的内容本身会抛出以下信息:

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;    </button>
<h3>Change Your Password</h3>
</div>
<div class="modal-body">
<form>
    <fieldset>
        <label>Your current password</label>
        <input type="password" placeholder="password">
        <label>Confirm current password</label>
        <input type="text" placeholder="password">

        <button type="submit" class="btn">Submit</button>
    </fieldset>
</form>
</div>
<div class="modal-footer">
    <a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>
</div>

但是,对于显示远程内容的模态框,我相信我应该已经显示 modal-body 类:

<div class="modal fade hide" id="ajax">
    <div class="modal-body">
        <p>body content to be replaced</p>
    </div>
</div>

我该如何解决这个问题,提供完整的模态 div 内容并使其正确显示?

【问题讨论】:

    标签: twitter-bootstrap modal-dialog


    【解决方案1】:

    您似乎想用网页填充模态正文。您可以使用 a 标记和 data-target 属性调用模式:

    &lt;a id="file_attach" data-toggle="modal" href="http://fiddle.jshell.net/jhfrench/6K8rD/show/" data-target="#utility" class="btn"&gt;Modal 1&lt;/a&gt;

    Twitter documentation 笔记

    如果提供了远程 url,内容将通过 jQuery 的 load 加载 方法并注入.modal-body。如果您正在使用数据 api,您也可以使用 href 标签来指定远程 来源。

    有关示例,请参阅 http://jsfiddle.net/jhfrench/qv5u5/(有关如何在多个调用链接之间重用一个模式的详细信息,请参阅 How can I reuse one Bootstrap modal div?)。

    【讨论】:

    • 请注意,页面是通过 AJAX 加载到模式中的,因此受“同源策略”限制(即:您将无法将 awesomesite.com 加载到托管的 div 中在 myapp.com)。
    • 这是否意味着href返回的响应应该是AJAX响应?或者我们可以从同一个应用程序中获取其他页面。
    • @mutant:对不起,我不明白你的问题。
    • 它工作正常。我的印象是它需要 json 响应,但事实并非如此。抱歉,您的问题令人困惑,感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    相关资源
    最近更新 更多