Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter04 : input_check 본문

WEB.JS/09.FORM_JS

chapter04 : input_check

GAWON 2023. 5. 22. 09:29
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
	.success{color: blue;}
	.fail{color: red;}
</style>
<script type="text/javascript">
	function check(){
		var num = document.forms.myForm.num.value;
		var result = document.querySelector("#result");
		var msg = '';
		
		if(num > 0 && num < 11){
			// 정상
			msg = '정상 범위입니다.';
			result.classList.add('success');
			//result.classList.remove('success');	// 클래스 삭제 함수
		}else{
			// 비정상
			msg = '비정상 범위입니다.';
			//result.className = 'fail';
			result.setAttribute("class", 'fail');
		}
		
		result.innerHTML = msg;
	}
</script>
</head>
<body>
	<form action="#" name="myForm">
		1 ~ 10 사이 정수
		<input type="number" id="num" name="num">
		<input type="button" value="검증" onclick="check()">
	</form>
	<br/>
	<div id="result"></div>
</body>
</html>

'WEB.JS > 09.FORM_JS' 카테고리의 다른 글

chapter02 : input_check  (0) 2023.05.22
chapter03 : input_check  (0) 2023.05.22
chapter05_regExp  (0) 2023.05.22
chapter06 : join_정규식  (0) 2023.05.22
chapter06 : join  (0) 2023.05.22