读书人

js中的鼠标事件的onmouseover和onmous

发布时间: 2012-05-23 13:44:13 作者: rapoo

【求助】js中的鼠标事件的onmouseover和onmouseout怎么用?
那位大哥能写个小例子给我看看么。。。非常感谢

[解决办法]
<div>
<a onmouseover="mouseOver(this)" onmouseout="mouseOut(this)">鼠标放在上面就知道了</a>
</div>

<script type="text/javascript">
function mouseOver(o) {
o.style.backgroundColor = "red";
}
function mouseOut(o) {
o.style.backgroundColor = "blue";
}
</script>
[解决办法]

HTML code
<!DOCTYPE HTML><html>    <head>        <meta charset="gb2312" />        <title></title>            </head>    <body>        <div id="test" style="border:1px solid red;">移动上来</div>        <script>            function $(el){                return typeof el == 'string' ? document.getElementById(el) : el;            }            $('test').onmouseover=function(){                this.style.border = '2px solid blue';            }            $('test').onmouseout = function(){                this.style.border = '2px solid red';            }        </script>    </body></html>
[解决办法]
上面已有答案了。

读书人网 >JavaScript

热点推荐