溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何解決bootstrap模態(tài)框數(shù)據(jù)緩存的問(wèn)題

發(fā)布時(shí)間:2021-07-21 11:05:09 來(lái)源:億速云 閱讀:206 作者:小新 欄目:web開發(fā)

這篇文章主要介紹如何解決bootstrap模態(tài)框數(shù)據(jù)緩存的問(wèn)題,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

問(wèn)題背景

第一步進(jìn)行新增驗(yàn)證

如何解決bootstrap模態(tài)框數(shù)據(jù)緩存的問(wèn)題

第二步進(jìn)行修改模態(tài)框 驗(yàn)證信息沒有消除 且表單數(shù)據(jù)被緩存

如何解決bootstrap模態(tài)框數(shù)據(jù)緩存的問(wèn)題

模態(tài)框代碼:新增修改共用一個(gè)模態(tài)框

<!-- 模態(tài)框(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">
&times;
</button>
<h5 class="modal-title" id="myModalLabel">
標(biāo)題
</h5>
</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" >關(guān)閉</button>
<button type="button" class="btn btn-primary" onclick="save()">提交</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>

js代碼

//驗(yàn)證設(shè)置

$(function(){ 
$("#form1").bootstrapValidator({
feedbackIcons: {
 valid:"glyphicon glyphicon-ok",
 invalid:"glyphicon glyphicon-remove",
 validating:"glyphicon glyphicon-refresh"
 },
fields : { 
"unitName" : {

validators : {
notEmpty : {
message : '單位名稱不能為空'
}
}
}
}
});
});

  //重置表單數(shù)據(jù)
$(function() { 
 $("#myModal").on('hide.bs.modal',function() {
 //關(guān)閉后重置表單數(shù)據(jù)
 $("#form1").data('bootstrapValidator').resetForm(); 


 });
 
 $("#myModal").on('show.bs.modal',function() {
 //打開前重置表單數(shù)據(jù)
 $("#form1").data('bootstrapValidator').resetForm(); 
 });
});
function save() {

  //保存前開啟驗(yàn)證
$("#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);

     //關(guān)閉模態(tài)框
$('#myModal').modal('hide');
} else {
alert(result.message);
}
},
complete : function() {
},
error : function(data) {
alert("error");
}
});
}}

最終解決效果

如何解決bootstrap模態(tài)框數(shù)據(jù)緩存的問(wèn)題

如何解決bootstrap模態(tài)框數(shù)據(jù)緩存的問(wèn)題

以上是“如何解決bootstrap模態(tài)框數(shù)據(jù)緩存的問(wèn)題”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI