用bootstrapValidator的resetForm()方法:
<!-- // create server begin -->
<div class="modal fade" id="server-create-server-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-create">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="clearValidate('server-create-server-modal-form')">
×
</button>
<h4 id="headDeptLable" class="modal-title">创建存储服务器 </h4>
</div>
<form id="server-create-server-modal-form" method="post" class="form-horizontal" action="">
<div class="modal-body">
<!-- // modal-body begin -->
<div class="form-group">
<label class="col-lg-4 col-md-4 col-sm-4 control-label font-normal align-right">名称:</label>
<div class="col-lg-5 col-md-5 col-sm-5">
<input type="text" class="form-control" id="server-create-server-modal-name" name="serverCreateServerModalName" placeholder="" />
</div>
</div>
<div class="form-group">
<label class="col-lg-4 col-md-4 col-sm-4 control-label font-normal align-right">类型:</label>
<div class="col-lg-5 col-md-5 col-sm-5">
<select id="server-create-server-modal-type" name="serverCreateServerModalType" class="form-control">
<option value="">请选择</option>
<option value="AU">存储MMJ</option>
<option value="CA">服务器二</option>
<option value="FR">服务器三</option>
<option value="DE">服务器四</option>
<option value="IT">服务器五</option>
<option value="JP">服务器六</option>
<option value="GB">服务器七</option>
<option value="US">服务器八</option>
<option value="VN">服务器九</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-4 col-md-4 col-sm-4 control-label font-normal align-right">IP:</label>
<div class="col-lg-5 col-md-5 col-sm-5">
<input type="text" class="form-control" id="server-create-server-modal-ip" name="serverCreateServerModalIp" />
</div>
</div>
<!-- // modal-body end -->
</div>
<div class="modal-footer">
<button class="btn btn-success" id="server-create-server-modal-submit" type="submit">
确 定
</button>
<button class="btn btn-default" type="button" data-dismiss="modal" onclick="clearValidate('server-create-server-modal-form')">
取 消
</button>
</div>
</form>
</div><!-- /Modal -->
</div>
</div><!-- // create server end -->
$('#server-create-server-modal-form')
.bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
serverCreateServerModalName: {
message: '名称无效',
validators: {
notEmpty: {
message: '名称不能为空'
},
stringLength: {
min: 1,
max: 30,
message: '名称只能为1至30个字符'
},
regexp: {
regexp: /^[a-zA-Z0-9_\.]+$/,
message: '名称只能为数字字母下划线'
}
}
},
serverCreateServerModalType: {
message: '类型无效',
validators: {
notEmpty: {
message: '类型不能为空'
}
}
},
serverCreateServerModalIp: {
message: 'IP码无效',
validators: {
notEmpty: {
message: 'IP不能为空'
},
regexp: {
regexp: /^(\d|\d\d|1\d\d|2[0-4]\d|25[0-5])(?:\.(\d|\d\d|1\d\d|2[0-4]\d|25[0-5])){3}$/g,
message: '请输入正确的IP'
}
}
}
}
})
.on('success.form.bv', function(e) {
e.preventDefault();//取消submit默认提交效果
$("#server-create-server-modal-form")[0].reset();//重置表单,此处用jquery获取Dom节点时一定要加[0]
$("#server-create-server-modal-form").data('bootstrapValidator').resetForm();//清除当前验证的关键之处
$("#server-create-server-modal").modal("hide");
toastr.success("创建服务器成功", "成功提示");
$serverTable.bootstrapTable("refresh");
});
版权声明:本文为duansamve原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。