我有以下javascript代碼來驗證用戶名和密碼的簡單登錄表單 - 這是一個asp.net自定義驗證程序的客戶端驗證,如果這有所幫助。jQuery - 只有在所有表單字段都有效的情況下才能運行加載圖形函數
function userValidation(source, arguments) {
if (arguments.Value != "" && arguments.Value != "User name") {
if($(source).parents(".loginPanel").find(".errorAsterisk[style*='visible']").length==0) {
$(source).parents(".loginPanel").css({ "background-color": "" });
}
arguments.IsValid = true;
} else {
$(source).parents(".loginPanel").css({ "background-color": "#ECC8C8" });
arguments.IsValid = false;
}
}
function passwordValidation(source, arguments) {
var passVal = /^((?![<>]).){1,64}$/;
if (arguments.Value != "" && arguments.Value != "Password" && passVal.test(arguments.Value)) {
if($(source).parents(".loginPanel").find(".errorAsterisk[style*='visible']").length==0) {
$(source).parents(".loginPanel").css({ "background-color": "" });
}
arguments.IsValid = true;
} else {
$(source).parents(".loginPanel").css({ "background-color": "#ECC8C8" });
arguments.IsValid = false;
}
}
我也希望當用戶成功地填補了形式出現「正在加載」消息 - 這是我對這些代碼...
$(".loginPanel").on("click", "input[id*='Login']", function() {
loadingPage2("", "Logging in...");
});
麻煩的是,加載功能即使頁面無效,也會運行。
任何想法,我可以包括它,所以它只運行,如果的一切有效?
感謝
嗯,我擔心你會這樣說,因爲我有很多其他地方需要添加加載圖形。是否可以將var設置爲數組並檢查數組中的所有條目是否爲真? – Tom
如果您不需要知道哪個值爲false,請使用:var x = []'並添加每個函數'x.push(true);'。你需要知道哪個值失敗了嗎? (如果我知道的話,我可以更新答案) – Rikard
我只需要知道某件事是無效的...... – Tom