JavaScript OnMouseOut事件 怎么用JS控制表格中<tr>的onmouseover和onm...

javascript onmouseover\u548conmouseout\u4e8b\u4ef6

\u8fd9\u4e0d\u662f\u7a0b\u5e8f\u7684\u95ee\u9898\u62c9\uff0c\u662f\u4f60\u8bbe\u8ba1\u7684\u95ee\u9898


\u4f60\u5199\u7684 onMouseOut="HideMenu" \u5440\uff0c\u4e0d\u662f\u5f53\u9f20\u6807\u79fb\u5f00 a \u6807\u7b7e\u7684\u65f6\u5019 \u5c31\u5173\u95ed\u8fd9\u4e2a\u83dc\u5355\u5417\u3002

\u8fd9\u91cc\u5176\u5b9e\u628a\u4f60\u7684\u9f20\u6807\u52a8\u4f5c\u89c4\u5212\u6e05\u695a\u5c31\u597d\u4e86\uff0c\u81f3\u4e8e\u4ee3\u7801\u8981\u770b\u4f60\u7a76\u7adf\u60f3\u8981\u8fbe\u5230\u4ec0\u4e48\u76ee\u7684\u3002

\u5047\u8bbe\uff0c\u4f60\u7684\u83dc\u5355\u8ddd\u79bba\u6807\u7b7e\u6bd4\u8f83\u8fdc\uff0c\u90a3\u4e48\u5c31\u4e0d\u5e94\u8be5\u5199 a \u6807\u7b7e\u7684 onMouseOut \u4e8b\u4ef6\uff0c\u56e0\u4e3a\u6765\u4e0d\u53ca\u70b9\u51fb\u80af\u5b9a\u5c31\u5173\u95ed\u4e86\uff0c\u5e94\u8be5\u662f \u5728\u5176\u4ed6\u7684\u4f4d\u7f6e\u4e0a\u6bd4\u5982 body\u4e0a\uff08\u5c31\u662f\u4e0d\u5728a\u6807\u7b7e\u4e5f\u4e0d\u5728\u4f60\u7684\u83dc\u5355\u4e0a\uff09\u6dfb\u52a0onMouseOver \u4e8b\u4ef6\u6765\u5173\u95ed\u4f60\u7684\u83dc\u5355\u3002\u8fd9\u6837\u4ecd\u7136\u9700\u8981\u4fdd\u8bc1\u4f60\u7684\u9f20\u6807\u5728\u79bb\u5f00a\u65f6\u6ca1\u6709\u8fdb\u5165body\u7684\u7a7a\u95f4\uff0c\u800c\u76f4\u63a5\u8fdb\u5165\u5230\u4e86\u83dc\u5355\u4e0a\u3002

\u5176\u5b9e\u5b8c\u5168\u53ef\u4ee5\u7b49\u4f60\u70b9\u51fb \u83dc\u5355\u540e\u518d\u5173\u95ed\u83dc\u5355\uff0c\u5e76\u4e14\u5728\u70b9\u51fb \u5176\u4ed6\u7a7a\u767d\u65f6\u5173\u95ed\u83dc\u5355\uff0c
\u53ea\u7528 \u9f20\u6807\u79fb\u5165\u79fb\u51fa\u505a\u529f\u80fd \u7528\u8d77\u6765\u5f88\u8d39\u52b2\u7684\uff0c\u56e0\u4e3a\u4e00\u822c\u7684\u4eba\u5728\u6d4f\u89c8\u7f51\u9875\u65f6\u9f20\u6807\u662f\u6643\u6765\u6643\u53bb\u7684\u3002

\u5faa\u73af\u6240\u6709\u884c\uff0c\u7ed9\u6bcf\u884c\u6dfb\u4e0a\u8fd9\u4e24\u4e2a\u4e8b\u4ef6\u3002
\u6bcf\u4e00\u884c\u90fd\u7528\u4e00\u4e2a
\u7136\u540e\u5199\u7684CSS

<!--
a.tra : hover {color: #FF00FF; }
-->



efdsfaf
dsfdfa


sdfsaf
dfasdfsdf

javascript onmouseover和onmouseout事件
onmouseover和onmouseout鼠标移入移出时触发的事件:
onmouseover 用户鼠标移入元素时触发的事件。并执行onmouseover调用的函数。
onmouseout 用户鼠标移开元素时触发的事件。并执行onmouseout调用的函数。
onmouseover和onmouseout 这两个事件在javascript中较常用。
下面通过一个示例更深入了解这两个事件的使用:
示例:鼠标移入时,改变字体的背景色,移出时,还原默认的背景色。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>鼠标移入时,改变字体的背景色,移出时,还原默认的背景色。</title>
<style>
.xuexi{width:200px;height:120px;background:#abcdef;border:1px solid green;}
</style>
<script>
function aixuexi(){
var woaixuexi=document.getElementById("woaixuexi");
woaixuexi.style.background="yellowgreen";
}
function xuexi(){
var xuexi=document.getElementById("woaixuexi");
xuexi.style.background="#abcdef";
}
</script>
</head>
<body>
<div id="woaixuexi" onmouseover="aixuexi();" onmouseout="xuexi();" class="xuexi"></div>
</body>
</html>

onmouseleave和onmouseenter是IE的特有方法,主要就是因为js的冒泡问题引起的,如果要做到跨浏览器的话你可以把这个方法改造下
function out(){
document.getElementById("apDiv1").style.display="none";
}

思路1
function out(e){
e=e||window.event;
var evetObj=window.event.srcElement;
//在此判断事件Obj是div的子对象或者是div本事 就不隐藏
}
思路2
就是从事件冒泡上下手。

有一个很简单的方法可以解决.你可以试一下.
即为div添加onmouseover事件.用onmouseover事件抵消对div内部元素对onmouseout的触发.
<div id="apDiv1"onmouseout="out()" onmouseover="javascript:this.style.display='block';" style="background-color:#F00 ;

position:absolute ; left:150px; height:150px; height:150px;

width:150px;">
<a href="#">为什么鼠标移动到这里div就失去焦点了</a>
</div>

====================
重点在此:
onmouseover="javascript:this.style.display='block';"
兼容ie,firefox.你可以试试.

用onmouseleave可以了
不过onmouseleave只在IE有效。
要兼容浏览器的话可以考虑用jQuery里的hover方法

扩展阅读:china visa services ... javascript cookie ... xbox one x xbox series x ... javascript dom bom ... air jordan 1 nova xx ... javascript console ... javascript&jquery ... free xbox live code ... free proxy master ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网