Jquery 引导模式不更新adminlte中的内容并重置表单
当我打开带有数据的模式并将其关闭然后再次打开时,表单不会重置并显示旧的数据 如何修复它并初始化表单数据 我使用bootstrap v3.3.7和adminlte v2 模态html:Jquery 引导模式不更新adminlte中的内容并重置表单,jquery,spring-boot,bootstrap-modal,adminlte,Jquery,Spring Boot,Bootstrap Modal,Adminlte,当我打开带有数据的模式并将其关闭然后再次打开时,表单不会重置并显示旧的数据 如何修复它并初始化表单数据 我使用bootstrap v3.3.7和adminlte v2 模态html: <div class="modal fade" id="new" tabindex="-1" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"&g
<div class="modal fade" id="new" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-body">
<img src="/image/loading.gif" class="loading"/>
<span>Lodaing . . .</span>
</div>
</div>
</div>
</div>
将其放入页面的javascript中,以在关闭时清除模式内容:
$(document).on('hidden.bs.modal', '.modal', function (e) {
// Handles the event thrown when a modal is hidden
$(this).removeData('bs.modal');
$(this).find(".modal-content").empty();
});
很明显,每次打开和关闭模态时,模态内容都会保持打开状态,应使用以下代码清除模态内容:
$(document).on('hidden.bs.modal','.modal',函数(e){
$(this.find(“.modal content”).empty();
$(this.removeData('bs.modal');
});代码>
编辑
洛丹。
向我们展示您的代码展示您的代码。检查你的JS是否正在请求新数据并在你打开它时更新你的模式。参考链接,你可以从你的问题中得到答案:为什么这个答案被否决?答案是正确的。
@RequestMapping(value = "/edit")
public String edit(Model model,
@ModelAttribute(value = "id") String paramId){
if (paramId == 0){
//open modal without data...
}
if (paramId != 0){
//open modal with data...
}
model.addAttribute("edit", data);
return "view/edit"; //open modal html template
}
$(document).on('hidden.bs.modal', '.modal', function (e) {
// Handles the event thrown when a modal is hidden
$(this).removeData('bs.modal');
$(this).find(".modal-content").empty();
});