在我的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;
}
concat所有alertValidation合併成一個,然後提醒那條消息 –
@EricFrick是的,這是我遇到的問題,我如何連接消息? – user1881090