3

我有一个脚本,使用 onmouseover 使元素显示 = 块

<script language="JavaScript">
function aaa() 
{
    document.getElementById('cat').style.display = "block";
}
</script>

<a href='#' onmouseover='aaa()'>hover on me</a>

<div  id='cat' style='display:none;'>this will show</div>

当鼠标不在

"<a href='#' onmouseover='aaa()'>hover on me</a>"

我怎样才能做到这一点?

4

5 回答 5

7

onmouseout活动

function bbb() 
{
    document.getElementById('cat').style.display = "none";
}

...

<a href='#' onmouseover='aaa()' onmouseout='bbb()'>hover on me</a>
于 2012-09-05T06:01:12.313 回答
3

演示:http: //jsfiddle.net/TRxRV/1/

HTML:

<a href='#' onmouseover='show();' onmouseout='hide();'>hover</a>
<div  id='cat' style='display:none;'>cat</div>​

JavaScript:

window.show = function () {
    document.getElementById('cat').style.display = "block";
}

window.hide = function () {
    document.getElementById('cat').style.display = "none";
}
于 2012-09-05T06:03:20.860 回答
3

这应该可以帮助你...

                function aaa()
                {
                    document.getElementById('cat').style.display = "block";
                }
                function bbb()
                {
                    document.getElementById('cat').style.display = "none";
                }

        <a href='#' onmouseover='aaa()' onmouseout="bbb();">hover on me</a>
        <div id='cat' style='display: none;'>this will show</div>
于 2012-09-05T06:05:03.230 回答
3

我正在考虑您提供的相同代码作为示例。如果您在 onMouseout() 函数中包含原始显示属性,则当鼠标未悬停时,您将返回原始属性。

<script language="JavaScript">
function aaa() 
{
    document.getElementById('cat').style.display = "block";
}
function bbb()
{
//include the code TO CHAGE THE PROPERTY HERE
document.getElementById('cat').style.display = "      ";
}
</script>

<a href='#' onmouseover='aaa();' onmouseout="bbb();">hover on me</a>

<div  id='cat' style='display:none;'>this will show</div>
于 2012-09-05T06:06:18.900 回答
2

你应该onMouseOut为此使用事件,代码看起来像

<a href='#' onmouseover='show();' onmouseout='dontShow();'>hover</a>
<div  id='cat' style='display:none;'>this will show</div>​



function show() {
    document.getElementById('cat').style.display = "block";
}

function dontShow() {
    document.getElementById('cat').style.display = "none";
}
于 2012-09-05T06:02:42.047 回答