Bootstrap 3 - 如何通过 AJAX 在模态正文中加载内容? [英] Bootstrap 3 - How to load content in modal body via AJAX?

查看:30
本文介绍了Bootstrap 3 - 如何通过 AJAX 在模态正文中加载内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您在此处所见,我有一个启动模态的按钮.为按钮设置一个 href url 这个 url 会被 Bootstrap 3 自动加载到模态中.事实是此页面已加载到模态根目录中(如模态用法的引导程序 3 文档 中所述).我想将其加载到模态正文中.

As you can see here, I have a button that launches a modal. Setting an href url for the button this url is automatically loaded into modal by Bootstrap 3. The fact is this page is loaded into modal root (as said in the bootstrap 3 documentation for modals usage). I want to load it into the modal-body instead.

有没有办法通过属性(不是javascript)来做到这一点?或者最自动化的方法是什么?

Is there a way to do it via attributes (not javascript)? Or what is the most automatic way to do it?

附言我记得在 Bootstrap 2 中,内容加载到正文中,而不是根目录中.

P.S. I remember in Bootstrap 2 the content was loaded in the body, not the root.

推荐答案

检查 this SO answer 出.

看起来唯一的方法是为整个模态结构提供 ajax 响应.

It looks like the only way is to provide the whole modal structure with your ajax response.

正如您可以从引导程序中查看源代码,加载函数绑定到根元素.

As you can check from the bootstrap source code, the load function is binded to the root element.

如果您无法修改 ajax 响应,一个简单的解决方法可能是在您的 body 元素上显式调用 $(..).modal(..) 插件,即使它可能会破坏根元素的显示/隐藏功能.

In case you can't modify the ajax response, a simple workaround could be an explicit call of the $(..).modal(..) plugin on your body element, even though it will probably break the show/hide functions of the root element.

这篇关于Bootstrap 3 - 如何通过 AJAX 在模态正文中加载内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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