事件冒泡,用onmouseleave替换onmouseout,我本机的ie8没问题,
然后用jquery来bind,火狐和ie8都没问题,可是朋友用ie6和ie7试了下都不行哦,还是事件冒泡
不是说ie都支持onmouseleave吗?为毛就ie8可以,ie6、7都不行呢
然后用jquery来bind,火狐和ie8都没问题,可是朋友用ie6和ie7试了下都不行哦,还是事件冒泡
不是说ie都支持onmouseleave吗?为毛就ie8可以,ie6、7都不行呢
解决方案 »
- js动态加载Google广告的问题
- 世界上最好用的纯前端模板【没有之一】,AceTemplate高调亮相。
- 通过ajax获取到html后,怎么执行其中的第一个方法???
- 关于图片预加载的问题
- 帮我看看这段JavaScript函数哪里错了!
- 如何防止看状态,防止查看文件地址路径
- 请问有没有办法让浏览器地址栏不显示我get提交的数据?
- 国内一所学校出的题目:正则表达式来解 。看似 很简单,其实不然
- 大家研究一个策略问题
- 在客户端怎样用javascript检测某个文件是否存在??急!!!!
- ajax post 怎样设置 同步 async:false
- 莫名奇妙网页代码中多了一行这么个玩意儿,浏览器报出有恶意软件
考虑到兼容性,一般就用onmouseout。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.onload=function(){
var p=document.getElementById("test"); p.onmouseout=function(){p.style.display="none"};
}
//-->
</SCRIPT>
<BODY>
<div id="test" style="background-color:Red">
<a class="b">aaaaaaaaaaaaa</a><br />
<a class="b">aaaaaaaaaaaaa</a><br />
<a class="b">aaaaaaaaaaaaa</a><br />
<a class="b">aaaaaaaaaaaaa</a><br />
<a class="b">aaaaaaaaaaaaa</a><br />
</div>
</BODY>
</HTML>鼠标移出div时隐藏该div。可惜现在鼠标移到a标签时div也隐藏了
在线等大虾
楼主看看那这个
结果是ie8、火狐没问题,ie6、tt、搜狗都不行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset="gb2312" />
<style type="text/css">
a
{
font-size: 12px;
text-decoration: none;
color: Green;
margin:10px 5px;
}
</style>
<script type="text/javascript">
function contextMenuOperation(event) {
var e = event || window.event;
e.returnValue = false;
var img = document.getElementById("img_Person");
img.contextmenu = function() { return false; }
var div = document.getElementById("div_ContextMenu");
var left = e.clientX;
var top = e.clientY;
div.style.display = "block";
div.style.position = "absolute";
div.style.left = left + "px";
div.style.top = top + "px";
}
function contextMenu(event) {
var e = event || window.event;
var img = document.getElementById("img_Person");
img.contextmenu = function() { return false; }
var div = document.getElementById("div_ContextMenu");
if(test(div,e)){
var left = e.clientX;
var top = e.clientY;
div.style.display = "none";
div.style.position = "absolute";
div.style.left = left + "px";
div.style.top = top + "px";
e.returnValue = false;
}
}if(typeof(HTMLElement)!="undefined") // 给firefox定义contains()方法,ie下不起作用
{
HTMLElement.prototype.contains=function(obj)
{
while(obj!=null&&typeof(obj.tagName)!="undefind"){ //通过循环对比来判断是不是obj的父元素
if(obj==this) return true;
obj=obj.parentNode;
}
return false;
};
} function test(obj, e) {
if (e.currentTarget) {
if (e.relatedTarget != obj) {
if (obj != e.relatedTarget.parentNode && !obj.contains(e.relatedTarget)) {
return true;
}
}
} else {
if (e.toElement != obj) {
if (obj != e.toElement.parentNode && !obj.contains(e.toElement)) {
return true;
}
}
}
}</script>
</head>
<body>
<div>
<img id="img_Person" style="cursor:pointer;" oncontextmenu="return false;" onmousedown="contextMenuOperation(event);" src="Images/girl.jpg" alt="原圖"/>
</div>
<div id="div_ContextMenu" style="border:1px solid green;width:150px;height:100px;display:none;" OnMouseOut="contextMenu(event);">
<ul style="list-style: none; list-style-type:none;margin:0px;background-color:White;">
<li><a id="isFrame2" href="#"><font algin="center">弹出</font></a></li>
<li><a href="#"><font algin="center">搜狐</font></a></li>
</ul>
</div>
</body>
</HTML>楼主这个可以试试