Bootstrap模态动态内容 [英] Bootstrap Modal Dynamic Content

查看:68
本文介绍了Bootstrap模态动态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种可以随时更改的动态内容加载方法.根据Bootstrap文档

I'm in need of a method to load dynamic content that can change at any time. According to the Bootstrap documentation

<a data-toggle="modal" href="remote.htm" data-target="#modal">Click me</a>

正在使用jQuerys的 .load ,仅加载内容一次.它将内容注入到modal-content div中.如前所述,该模态的内容可以在任何给定时间更改,因此我需要一种不同的方法.有什么想法吗?

is making use of the jQuerys' .load only loading the content once. It injects the content in the modal-content div. As previously stated the content of this modal can be changed at any given time and therefore I need a different method. Any ideas?

TL; DR-我正在寻找一种方法,该方法将在每次模式打开时加载动态内容(远程),而不是一次(默认的Bootstrap模式).

TL;DR - I'm looking for a method that will load dynamic content (remote) every time the modal opens instead of once (default Bootstrap modal).

推荐答案

如果您的用户可以忍受延迟,请在显示事件发生时重新加载内容.

If your users can tolerate the delay, reload the content whenever the show event occurs.

$('#modal').on('show.bs.modal', function(){
    $.get("remote.htm", function(data){
        $('#modal').find('.modal-content').html(data);
    })
})

根据需要添加错误处理和参数

Add error handling and parameters as needed

这篇关于Bootstrap模态动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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