解决bootstrap模态框数据缓存的问题方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了解决bootstrap模态框数据缓存的问题方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2299字,纯文字阅读大概需要4分钟。
内容图文
问题背景
第一步进行新增验证
第二步进行修改模态框 验证信息没有消除 且表单数据被缓存
模态框代码:新增修改共用一个模态框
<!-- 模态框(Modal) --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button> <h4 class="modal-title" id="myModalLabel"> 标题 </h4> </div> <div class="modal-body"> <form id="form1" class="form-horizontal" role="form"> <input type="hidden" id="unitId" name="unitId"/> <div class="form-group"> <label class="control-label col-sm-2" for="">单位名称</label> <div class="col-sm-8"> <input type="text" class="form-control" id="unitName" name="unitName"> </div> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal" >关闭</button> <button type="button" class="btn btn-primary" onclick="save()">提交</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal --> </div>
js代码
//验证设置 $(function(){ $("#form1").bootstrapValidator({ feedbackIcons: { valid:"glyphicon glyphicon-ok", invalid:"glyphicon glyphicon-remove", validating:"glyphicon glyphicon-refresh" }, fields : { "unitName" : { validators : { notEmpty : { message : '单位名称不能为空' } } } } }); }); //重置表单数据 $(function() { $("#myModal").on('hide.bs.modal',function() { //关闭后重置表单数据 $("#form1").data('bootstrapValidator').resetForm(); }); $("#myModal").on('show.bs.modal',function() { //打开前重置表单数据 $("#form1").data('bootstrapValidator').resetForm(); }); }); function save() { //保存前开启验证 $("#form1").bootstrapValidator("validate"); if($("#form1").data("bootstrapValidator").isValid()){ $.ajax({ url : "${path}/center/unit/save.action", data : $('#form1').serialize(), type : "post", dataType : "json", beforeSend : function() { // loading show }, success : function(result) { if (result.success) { search(); alert(result.message); //关闭模态框 $('#myModal').modal('hide'); } else { alert(result.message); } }, complete : function() { }, error : function(data) { alert("error"); } }); }}
最终解决效果
以上这篇解决bootstrap模态框数据缓存的问题方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
内容总结
以上是互联网集市为您收集整理的解决bootstrap模态框数据缓存的问题方法全部内容,希望文章能够帮你解决解决bootstrap模态框数据缓存的问题方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。