본문 바로가기
카테고리 없음

26. [springboot] JS 년도입력 . 찍어주기

by VIPeveloper 2020. 11. 5.
반응형

1. 서론

- 년도를 입력하면 2020.12.24 처럼 뒤에 자동으로 점을 찍어주고 싶었습니다.

- 나름 연구해서 쉽게 제작해보았습니다.

2. 본론

- 중요한 내용은 onkeypress인 것 같습니다. 키가 눌러질때 마다 인식을 해서, 길이를 비교하여 점을 찍어주는 문법입니다.

- 2020.12 , 2020.12.24 버전 두개로 만들어보았습니다.

<!DOCTYPE html>
<html>
<body>

<p>A function is triggered when the user is pressing a key in the input field.</p>

<input type="text" maxLength=7 id="test" onkeypress="month()">
<input type="text" maxLength=10 id="test2" onkeypress="day()">

<script>
function day() {
 	if(document.getElementById("test2").value.length==4 || 			document.getElementById("test2").value.length==7){
  		document.getElementById("test2").value += '.';
  	}
}
function month() {
 	if(document.getElementById("test").value.length==4){
  		document.getElementById("test").value += '.';
  	}
}
</script>

</body>
</html>

3. 결론

- 이상으로 년도 찍는 방법에 대해 알아보았습니다.

반응형