Twitter Bootstrap模式 - 加载"远程"内容

bea*_*ear 5 modal-dialog twitter-bootstrap

我正在尝试加载"远程"内容,基本上是通过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>
Run Code Online (Sandbox Code Playgroud)

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

<div class="modal fade hide" id="ajax">
    <div class="modal-body">
        <p>body content to be replaced</p>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

如何绕过这个,并提供完整的模态div内容并使其正确显示?

Jer*_*nch 3

您似乎想用网页填充模式主体。a您可以使用标签并使用数据目标属性来调用模式:

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

Twitter文档说明

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

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

  • 请注意,页面通过 AJAX 加载到模式中,因此受到“同源策略”限制(即:您无法将 Awesomesite.com 加载到 myapp.com 托管的 div 中)。 (2认同)