JavaScript

버튼클릭시 순서대로 숫자 호출

Bohemian life 2012. 6. 12. 16:59
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script>
	count=0;

	window.onload=function(){
		button1=document.getElementById("button1");
		button2=document.getElementById("button2");
		div1=document.getElementById("div1");
		
		write = function write(){
			count++;
			div1.innerHTML = div1.innerHTML + count;
		}
		start = function start(){
			//화면에 1,2,3,4 찍기
			auto=setInterval(write,500)//write를 0.5초마다 실행해라.
		}
		
		stop=function stop(){
			clearInterval(auto);
		}
		button1.onclick=start;
		button2.onclick=stop;
	}
</script>
</head>
<body>
	<button id="button1"> start </button>
	<button id="button2"> stop </button>
	<div id="div1" > </div>
</body>
</html>