본문 바로가기

개발하자/자바스크립트

onfocus,onblur

<html>
 <head>
 <script>
 window.onload=function(){
 t1.onfocus=f1;
 t2.onfocus=f1;
 t3.onfocus=f1;

t1.onblur=f2;
t2.onblur=f2;
t3.onblur=f2;
 }
 function f1(){
 this.style.backgroundColor="pink";
 }
 function f2(){
 this.style.backgroundColor="";
 }
 </script>
 </head>
 <body>
 <input type="text" id="t1">
 <input type="text" id="t2">
 <input type="text" id="t3">
 </body>
</html>