안녕하세요!

FE 개발자 유진주입니다.

Web/HTML+CSS+JS

[자바스크립트의 시작] Javascript 함수

ypearl 2023. 5. 3. 14:12

함수

: 코드의 유지보수 / 길이 / 가독성 측면에서의 장점들

<script>
	function nightDayHandler(self){
		var target=document.querySelector('body');
		if(self.value==='night'){
			target.style.backgroundColor='black';
			target.style.color='white';
			self.value='day'
		}
		else{
			target.style.backgroundColor='white';
			target.style.color='black';
			self.value='night'
		}
	}
</script>
<input type="button" value="night" onclick="nightDayHandler(this);">