我一直试图弄清楚这一点,我知道只要按钮是提交类型,就可以在表单中触发验证。但是我在视图上有一些其他选项卡,当我使用提交时,它会导致回发并返回到第一个选项卡。我不希望这种情况发生,所以我将验证放在一个函数中,并将按钮类型更改为按钮并删除了表单标签,并尝试在按钮单击事件上调用验证函数并且它没有触发。这可以在不使用表单标签的情况下完成吗?
我的代码是这样的...
$(document).ready(function () {
$("#btnUpdateModerator").click(function () {
ValidateIt();
});
ValidateIt();
});
function ValidateIt() {
var validator = $("#Users").bootstrapValidator({
feedbackIcons: {
valid: "glyphicon glyphicon-ok",
invalid: "glyphicon glyphicon-remove",
validating: "glyphicon glyphicon-refresh"
},
fields: {
DealerUsername: {
message: "Username is required",
validators: {
notEmpty: {
message: "Please Provide Username"
}
}
},
email: {
message: "Email address is required",
validators: {
notEmpty: {
message: "Please provide Email address"
},
emailAddress: {
message: "Email address was invalid"
}
}
},
password: {
validators: {
notEmpty: {
message: "Password is required"
},
stringLength: {
min: 6,
message: "Password must be at least 6 characters long"
},
different: {
field: "email",
message: "Email and Password cannot match"
}
}
},
confirmPassword: {
validators: {
notEmpty: {
message: "Confirm Password is required"
},
identical: {
field: "password",
message: "Password and Confirmation Password must match"
}
}
},
department: {
validators: {
notEmpty: {
message: "Department is Required"
}
}
}
}
});
}