首页 > 我想写一个JS的鼠标移入显示DIV的事件,但我这样的思路写出来不得行;求大神指教:

我想写一个JS的鼠标移入显示DIV的事件,但我这样的思路写出来不得行;求大神指教:

直接贴我写的代码哈:求大神给指证我的错误在哪里谢谢;

html<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>鼠标移入事件</title>
<style type="text/css">
.dj{
    width: 300px;
    height: 500px;
    background-color: #333333;
    display:none;
}
</style>
<script type="text/javascript">
window.onload = function (){
    var xod1=document.getElementById("as");
        xod1.onmouseover= function (){
            var xoda2=document.getElementById("dgil");
                xoda2.style.display='block';
        }
}
</script>
</head>
<body>
<div style="width: 50px; height: 50px;background: #33ccdd;" id="as"></div>
<div class="dj" id="dgil">dd</div>
</body>
</html>

可以实现当鼠标移入显示div的效果


谢谢各位大神哈;我今天到公司电脑上试了,又得行了。但火狐有些不是很灵的感觉。不每次都能触发;


题主是还想让其隐藏吗?

    <script type="text/javascript">
        window.onload = function (){
        var xod1=document.getElementById("as");
        xod1.onmouseover= function (){
            var xoda2=document.getElementById("dgil");
            if(xoda2.style.display=='none')
                xoda2.style.display='block';
            else
                xoda2.style.display='none';
        }
    }
    </script>

经过测试,完全正确。


确定这里面有错误?

【热门文章】
【热门文章】