bootstrapValidator动态添加校验字段
$("input:checkbox").on("ifChecked", function(event){
var cId = $(this).attr("name");
addField("seqNum"+cId,"顺序必填");
addField("discount"+cId,"折扣率必填");
});
$("input:checkbox").on("ifUnchecked", function(event){
console.log($(this).attr("name"))
var cId = $(this).attr("name");
removeField("seqNum"+cId);
removeField("discount"+cId);
});
function addField(field,notEmptyMsg){
$(".editForm").bootstrapValidator("addField", field,{
validators: {
notEmpty: {
message: notEmptyMsg
}
}
});
}
function removeField(field){
$(".editForm").bootstrapValidator("addField", field,{});
$(".editForm").bootstrapValidator("removeField", field)
}
相关推荐
本文实例为大家分享了bootstrapValidator表单验证的具体代码,供大家参考,具体内容如下。<div class="modal fade" id="details" tabindex="-1
在表单中,若对某一字段想添加验证规则,默认需要以<div class=”form-group”></div>包裹,内部<input class="form-control" />标签必须有name属性