首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js中的鼠标事件的onmouseover和onmouseout如何用

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

【求助】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>
[解决办法]
上面已有答案了。

热点排行