Bootstrap 模态对话框只加载一次 remote 数据的解决办法
来源:互联网 发布:暖气片 知乎 编辑:程序博客网 时间:2024/04/30 03:40
1. Bootstrap 模态对话框和简单使用
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">x</button>
<h3>对话框标题</h3>
</div>
<div class="modal-body">
<p>对话框主体</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">取消</a>
<a href="#" class="btn btn-primary" data-dismiss="modal">确定</a>
</div>
</div>
显示效果与下图相似:
可以使用按钮或链接直接调用模态对话框,这是简单的用法:
<button type="button" data-toggle="modal" data-target="#myModal">打开对话框</button>
<a href="#myModal" role="button" class="btn" data-toggle="modal">打开对话框</button>
这样只能把静态内容在对话框中显示出来,使用对话框的 remote 选项可以实现更强大的效果。
2. 使用 remote 选项让模态对话框加载页面到 .modal-body 中
有两种方法,一种是使用链接,另一种就是使用脚本。
2.1 使用链接
当点击此链接时,page.jsp 的内容会被加载到对话框的 .modal-body 中,随即显示对话框。
2.2 使用脚本
remote: "page.jsp"
});
这段脚本的效果和使用链接是一样的,当这段脚本执行后,page.jsp 的内容会被加载到对话框的 .modal-body 中,随即显示对话框。
这两种方法的背后,都是 Bootstrap 调用了 jQuery 的 load() 方法,从服务器端加载了 page.jsp 页面。但这个加载只会发生一次,后面不管你点击几次链接,或者执行几次脚本,哪怕改变传递给 remote 选项的值,对话框都不会重新加载页面,这真是个让人头疼的事情。不过问题还是能够解决的。
3. 移除数据,让对话框能够在每次打开时重新加载页面
在搜索并查阅了相关文档后,发现在对话框的 hidden 事件里写上一条语句就可以了:
$("#myModal").on("hidden", function() {
$(this).removeData("modal");
});
也可以在每次打开对话框之前移除数据,效果是一样的。
注:上面的代码基于 Bootstrap v2,如果使用 Bootstrape v3,模态对话框的 HTML 和事件的写法有一些不同,例如对于上面的 hidden 事件,要写成:
$("#myModal").on("hidden.bs.modal", function() {
$(this).removeData("bs.modal");
});
参考文档
Bootstrap 2.3.2 中文版文档——模态对话框
Twitter bootstrap remote modal shows same content everytime
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
- Bootstrap modal只加载一次 数据的解决办法
- 解决Bootstrap 模态对话框只加载一次请求数据问题
- bootstrap模态框(modal)使用remote方法加载数据,只能加载一次的解决办法
- bootstrap模态框(modal)使用remote方法加载数据,只能加载一次的解决办法
- jquery校验 remote缓存 remote只验证一次 解决办法
- bootstrap模态框内容只加载一次
- bootstrap 模态窗口 第二次无法加载js 的解决办法
- bootStrap-select从后台加载数据(动态加载数据)不成功的解决办法
- bootStrap异步加载数据(动态加载数据)一二级菜单点击失效的解决办法
- animation 只触发一次的解决办法
- 项目的js库只加载一次
- 使用easyUI的Tree实现授权功能
- JS操作JSON总结
- 菜鸟入门C#(四)
- cpp5.1
- 根据JSON数据,自动生成Table
- Bootstrap 模态对话框只加载一次 remote 数据的解决办法
- 线程加锁this详解
- 按钮点击事件的四种写法
- heap表按字符串和数值型排序规则
- 一天一条Linux指令-rm
- 【leetcode 343】Integer Break
- Android音频处理——通过AudioRecord去保存PCM文件进行录制,播放,停止,删除功能
- Hadoop 2.x分布式集群部署
- 关于学生成绩表的两个SQL题目