如何在包含表单的Bootstrap“远程”模式上进行验证?
jQuery验证不会自动应用于“远程”Bootstrap模式中加载的表单。
由于DOM中不存在表单,我们需要让验证器重新分析新添加的内容。幸运的是,Bootstrap有一个事件在显示模态后触发。
$(document).on("shown.bs.modal", function (e) {
$.validator.unobtrusive.parse(document);
});
注意事件名称使用“显示”而不是“显示”。
如果您在页面上混合使用本地和远程模态,则可能需要通过向模式div添加类来限制对远程模态的调用,如“remote-modal-form”。
$(".remote-modal-form").on("shown.bs.modal", function (e) {
$.validator.unobtrusive.parse($(".remote-modal-form"));
});