当前位置 : 主页 > 手机开发 > harmonyos >

Web_JavaScript_JS表单验证;

来源:互联网 收集:自由互联 发布时间:2023-08-26
Web_JavaScript_JS表单验证 script type="text/javascript"window.onload = function() {// 预约表单var formpt = document.getElementById("yyppFrom");var fstr = '';// 存储空值输入框名称;formpt.onsubmit = function() {// 姓名验证


Web_JavaScript_JS表单验证

<script type="text/javascript">
		window.onload = function() {
			// 预约表单
			var formpt = document.getElementById("yyppFrom");
			var fstr = '';	// 存储空值输入框名称;
			formpt.onsubmit = function() {
				// 姓名验证;
				var name = formpt.elements["name"];
				if(name.value == name.defaultValue) {
					name.style.borderColor = 'red';
					name.title = "请输入真实姓名!";
					if(fstr.indexOf(name.name)==-1){
						fstr += name.name+";";
					}
				}else {
					name.style.borderColor = '';
					name.title = "";
					if(fstr.indexOf(name.name)>-1) {
						fstr = fstr.replace(name.name+";","");
					}
				}
				// 电话验证
				var phone = formpt.elements["phone"];
				if(phone.value == phone.defaultValue) {
					phone.style.borderColor = 'red';
					phone.title = "请输入真实号码!";
					if(fstr.indexOf(phone.name)==-1){
						fstr += phone.name+";";
					}
				}else {
					phone.style.borderColor = '';
					phone.title = "";
					if(fstr.indexOf(phone.name)>-1) {
						fstr = fstr.replace(phone.name+";","");
					}
				}
				// 简述验证
				var jianshu = formpt.elements["jianshu"];
				if(jianshu.value == jianshu.defaultValue) {
					jianshu.style.borderColor = 'red';
					jianshu.title = "请输入您的病情!";
					if(fstr.indexOf(jianshu.name)==-1){
						fstr += jianshu.name+";";
					}
				}else {
					jianshu.style.borderColor = '';
					jianshu.title = "";
					if(fstr.indexOf(jianshu.name)>-1) {
						fstr = fstr.replace(jianshu.name+";","");
					}
				}
				// 提交时间
				var uptime = formpt.elements["uptime"];
				uptime.value =(new Date()).toLocaleString();
				
				// 是否提交
				var isOk = true;
				if(fstr.length >0) {
					isOk = false;
					// 焦点定位
					var fArray = fstr.split(";");
					formpt.elements[fArray[0]].focus();
				}		
				
				console.log(fstr);
				return isOk;
			}
		}
	</script>




上一篇:Web_PHP_使用PHPMailer类实现PHP邮件发送功能;
下一篇:没有了
网友评论