i구야 2015. 2. 14. 18:19

<html>
 <head>
 <script>
 window.onload=function(){
 var array=["red","green","blue"];
 var cnt=0;
 t1.onkeyup=function(){
 if(cnt==3) cnt=0;        //3번누르면 다시 cnt 값을 초기화시킴(배열에 색상을 3개밖에 입력해두지 않았으므로)
 t1.style.background=array[cnt];    //키누를때마다 텍스트필드 배경색이 변함
 cnt++;
 }
 }
 </script>
 </head>
 <body>
 <input type="text" id="t1">
 </body>
</html>