在我下面的 jquery 验证中,如果发生多个验证错误,我希望所有验证一次出现在警报中,而不是在警报中一次显示一个验证。如何在一个警报中显示所有消息?
function validation() {
var alertValidation = "";
var _qid = "";
var _msg = "";
$("input[data-type='qmark']").each(function(i) {
var questions = $(this).attr("data-qnum");
var marks = parseInt($("[class*=q" + i + "_ans_text]").text());
var txtinput = $(this).val();
_qid = questions;
_msg = "You have errors on Question Number: " + _qid + "\n";
if (txtinput == '') {
alertValidation += "\n\u2022 You have not entered in a value in all the Indivdiaul Marks textbox\n";
}
if (marks < '0') {
alertValidation += "Your Total Marks Remaining does not equal 0 \n\n\u2022 You Need To Remove " + Math.abs(marks) + " Marks";
}
if (marks > '0') {
alertValidation += "Your Total Marks Remaining does not equal 0 \n\n\u2022 You Have " + marks + " Marks Remaining";
}
if (alertValidation != "") {
return false; //Stop the each loop
}
});
if (alertValidation != "") {
alert(_msg + alertValidation);
return false;
}
return true;
}