論文設計中登陸所用到的JS代碼

 

var code; // 在全局 定義驗證碼
function createCode() {  //建立驗證碼函數
	code = new Array();
	var codeLength = 4;// 驗證碼的長度
	var checkCode = document.getElementById("checkCode");
	checkCode.value = "";

	var selectChar = new Array(1,2, 3, 4, 5, 6, 7, 8, 9,0,
			'a','b','c','d','e','f','g',
			'h','i','g','k','l','m','n',
			'o','p','q','r','s','t','u','v','w','x','y','z',
			'A', 'B', 'C', 'D', 'E',
			'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T',
			'U', 'V', 'W', 'X', 'Y', 'Z');

	for (var i = 0; i < codeLength; i++) {
		var charIndex = Math.floor(Math.random() * 62); // 取得隨機數的索引
		code += selectChar[charIndex];		// 根據索引取得隨機數加到code上
	}
	if (code.length != codeLength) {
		createCode();
	}
	checkCode.value = code;		// 把code值賦給驗證碼
}
function validate(){   //驗證非空函數
	
	var inputCode = document.getElementById("input1").value.toUpperCase();
	
		        // 判斷用戶名
		if($("input[name=userNumber]").val() == null || $("input[name=userNumber]").val() == ""){
		            alert("請輸入用戶名!");
		            $("input[name=userNumber]").focus();
		            return false;
		        }
		        // 判斷密碼
		else if($("input[name=password]").val() == null || $("input[name=password]").val() == ""){
		            alert("請輸入密碼!");
		            $("input[name=password]").focus();
		            return false;
		        }
		else if($("input:radio[name=role]:checked").val()== null){ 
			            alert("請選擇用戶角色!");
			            $("input[name=role]").focus();
			            return false;
			        }
		else if (inputCode.length <= 0) {
				alert("請輸入驗證碼!");
					return false;
					} 
		else if (inputCode != code.toUpperCase()) {
			alert(inputCode+"   "+code);
			alert("驗證碼輸入錯誤!請從新輸入");
			createCode();
			return false;
	} else {
		var from = document.getElementById("from");
		from.action = "login.user";   //登陸請求發送
	}
}
相關文章
相關標籤/搜索