当前位置: 代码迷 >> JavaScript >> onmouseout
  详细解决方案

onmouseout

热度:627   发布时间:2012-03-22 17:43:57.0
onmouseout 在线等
<script>
function   mclose2()
{
alert( "1111 ");
}
</script>
<div   class= "submenu "   id= "menu1 "   style= "border:1px   solid   red;width:100px;height:100px; "
            onmouseover= " "
            onmousemove= " "
            onmouseout= "mclose2() ">
                <a   href= "# "> HTML   Tutorials </a>
                <a   href= "# "> DHTML   Tutorials </a>
                <a   href= "# "> JavaScript   Tutorials </a>
                <a   href= "# "> CSS   Tutorials </a>
  </div>
为什么在div内移动时事件onmouseout不断触发

------解决方案--------------------
如果你移动到a标签也算移出div...
------解决方案--------------------
<script type= "text/javascript ">
var Class = {
//创建类
create: function () {
return function () {
this.initialize.apply(this, arguments);
};
}
};

var $A = function (a) {
//转换数组
return a ? Array.apply(null, a) : new Array;
};

var $ = function (id) {
//获取对象
return document.getElementById(id);
};

Object.extend = function (a, b) {
//追加方法
for (var i in b) a[i] = b[i];
return a;
};

Object.extend(Object, {

addEvent : function (a, b, c, d) {
//添加函数
if (a.attachEvent) a.attachEvent(b[0], c);
else a.addEventListener(b[1] || b[0].replace(/^on/, " "), c, d || false);
return c;
},

delEvent : function (a, b, c, d) {
if (a.detachEvent) a.detachEvent(b[0], c);
else a.removeEventListener(b[1] || b[0].replace(/^on/, " "), c, d || false);
return c;
},

reEvent : function () {
//获取Event
return window.event ? window.event : (function (o) {
do {
o = o.caller;
} while (o && !/^\[object[ A-Za-z]*Event\]$/.test(o.arguments[0]));
return o.arguments[0];
})(this.reEvent);
}

});

Function.prototype.bind = function () {
//绑定事件
var wc = this, a = $A(arguments), o = a.shift();
return function () {
wc.apply(o, a.concat($A(arguments)));
};
};

var out = {

d_m : null,

reMouse : function (a) {
var e = Object.reEvent();
return a ? document.body.scrollLeft + e.clientX : document.body.scrollTop + e.clientY;
},

set : function (o) {
var wc = this;
if (!wc.d_m)
wc.d_m = Object.addEvent(document, [ "onmousemove "], wc.over.bind(wc, o));
},

over : function (o) {
var wc = this, mouse_x = wc.reMouse(1), mouse_y = wc.reMouse(0),
left = o.offsetLeft, top = o.offsetTop, right = left + o.offsetWidth, bottom = top + o.offsetHeight;
if (left > mouse_x || right < mouse_x || top > mouse_y || bottom < mouse_y) {
alert( "onmouseout触发的说 ");
Object.delEvent(document, [ "onmousemove "], wc.d_m);
wc.d_m = null;
}
}

};
</script>
<div class= "submenu " id= "menu1 " style= "border:1px solid red;width:100px;height:100px; "