1. 程式人生 > >意見,郵箱,郵箱格式,圖片的驗證

意見,郵箱,郵箱格式,圖片的驗證

在這裡插入圖片描述

在這裡插入圖片描述

<div style="position:fixed; bottom: -0.1rem; width:100%;">
  <button type="button" class="mui-btn mui-btn-primary" style="width: 100%; padding: 15px;" id="commentSubmitBtn">提交評論</button>
</div>
// 點選提交按鈕
	$("#commentSubmitBtn").click(function () {
		var xhr = new XMLHttpRequest();
		xhr.open("post", 'http://192.168.188.1/nwmsucms/' + "page/service/evaluateAddSubmit");
		xhr.onreadystatechange = function () {
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					mui.alert("評論提交成功,謝謝您的寶貴意見", "溫馨提示", "確認", function (e) {
						if (e.index == 0) {
							window.location.reload();
						}
					});
				} else {
					mui.alert("評論提交失敗,請重新設定", "溫馨提示", "確認", function (e) {
						if (e.index == 0) {
							window.location.reload();
						}
					});
				}
			}
		};
		var commentImage = $("#commentImage")[0].files[0];
		var commentImageValue = $('input[name="commentImage"]').val();
		var commentEnvironmentValue = $("#commentEnvironmentValue").val();
		var commentServiceValue = $("#commentServiceValue").val();
		var commentFoodValue = $("#commentFoodValue").val();
		var commentInfo = $("#commentInfo").val();
		var commentEmail = $("#commentEmail").val();
		var regEmail = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
		if (commentEnvironmentValue == "") {
			mui.alert("機艙環境星級值不能為空", "溫馨提示", "確認");
			return false;
		} else if (commentServiceValue == "") {
			mui.alert("服務態度星級值不能為空", "溫馨提示", "確認");
			return false;
		} else if (commentFoodValue == "") {
			mui.alert("用餐口味星級值不能為空", "溫馨提示", "確認");
			return false;
		} else if (commentInfo == "") {
			mui.alert("請填寫您的意見或建議", "溫馨提示", "確認");
			return false;
		} else if (commentEmail == "") {
			mui.alert("請留下您的郵箱地址,我們會將反饋結果及時反饋給您", "溫馨提示", "確認");
			return false;
		} else if (!regEmail.test(commentEmail)) {
			mui.alert("您填寫的郵箱格式不正確,請重新輸入", "溫馨提示", "確認");
			return false;
		} else if (commentImageValue == "") {
			mui.alert("請對您認為不好的地方留下一張圖片,方便我們定位問題", "溫馨提示", "確認");
			return false;
		} else {
			var commentForm = new FormData();
			commentForm.append("commentEnvironmentValue", commentEnvironmentValue);
			commentForm.append("commentServiceValue", commentServiceValue);
			commentForm.append("commentFoodValue", commentFoodValue);
			commentForm.append("commentInfo", commentInfo);
			commentForm.append("commentEmail", commentEmail);
			commentForm.append("commentImage", commentImage);
			xhr.send(commentForm);
		}

	})
})