본문 바로가기

개발하자/자바스크립트

onmouseover,onmouseout

sol1)

<html>
<head>
<script>
function a(c){
c.style.background="red";
}
function b(c){
c.style.background="";
}
</script>
</head>
<body>
<input type="button" onmouseover="a(this)" onmouseout="b(this)">
</body>
</html>

sol2)

<html>
 <head>
<script>
 window.onload=function(){
btn.onmouseover=function(){
this.style.background="red";
}
btn.onmouseout=function(){
 this.style.background="";
}
 }
 </script>
 </script>
 </head>
 <body>
 <input type="button" id=btn>
 </body>
</html>

sol3)

<html>
<head>
<script>
window.onload=function(){
c.onmouseover=a;
c.onmouseout=b;
}
function a(){
this.style.background="red";
}
function b(){
this.style.background="";
}
</script>
</head>
<body>
<input type="button" id="c">
</body>
</html>