如何检测是否未安装在鼠标上

How to detect if not onmouseover?

本文关键字:安装 鼠标 是否 何检测 检测      更新时间:2023-09-26

我有一个脚本,使用onmouseover 使元素display=block

<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>"

我该怎么做?

存在onmouseout事件

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

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

演示: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";
}

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

<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>

这将帮助您

                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>

您应该使用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";
}