首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js怎么禁用一个事件

2012-04-09 
js如何禁用一个事件JScript code$(#right).mouseenter(function () {})$(#right).mouseleave(functio

js如何禁用一个事件

JScript code
$("#right").mouseenter(function () {});$("#right").mouseleave(function () {});//我想在执行mouseenter的时候把mouseleave给禁用掉,因为在FF浏览器里 mouseenter和mouseleave几乎是同时执行的


[解决办法]
$("#right").mouseenter(function () {});

$("#right").mouseleave(function () {return;});
行不!

[解决办法]
$("#right").unbind('mouseleave');
[解决办法]
探讨
JScript code

$("#right").mouseenter(function () {});

$("#right").mouseleave(function () {});
//我想在执行mouseenter的时候把mouseleave给禁用掉,因为在FF浏览器里 mouseenter和mouseleave几乎是同时执行的

[解决办法]
http://xiebiji.com/2010/02/js_mouseenter_mouseleave/?wptheme=Plainscape&ie=1

可以试试这个方法。。。
[解决办法]
我没试过。。你确定这2个有必然关系。。一个是进入事件,,,一个是离开事件。。可能同时触发?!
[解决办法]
onclick="javascript :return false;"

[解决办法]
你详细描述一下问题的症状,有可能是代码其它部分有问题。
光看这两行代码看不出来什么,通常这样写是不会有问题的。
[解决办法]
简单得很

$("#right").mouseenter(function () {$("#right").mouseleave=undefind;});


[解决办法]
event.PreventDefault()
[解决办法]
event.PreventDefault()
jquery中有这个函数的。
1.4应该是有的。
[解决办法]
HTML code
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>mouseerter与mouseover区别(IE下测试)</title> </head> <body> <div id="result" style="position:absolute;right:100px;top:5px;width:250px;height:400px;border:2px solid gray;overflow:auto;"> </div> <h3>1,鼠标在div[id=parent1]内部移动时也会触发mouseover事件</h3> <div id="parent1" style="width:400px;border:1px solid gray;padding:5px;"> <div id="child11" style="width:100px;height:100px;background:gold;float:left;">Child11</div> <div id="child12" style="width:100px;height:100px;background:gold;float:right;">Child12</div> <div style="clear:both;"></div> </div>  <h3>2,鼠标在div[id=parent2]内部移动时也不会触发mouseenter事件</h3> <div id="parent2" style="width:400px;border:1px solid gray;padding:5px;"> <div id="child21" style="width:100px;height:100px;background:gold;float:left;">Child21</div> <div id="child22" style="width:100px;height:100px;background:gold;float:right;">Child22</div> <div style="clear:both;"></div> </div> <script type="text/javascript"> function on(el,type,fn){ el.addEventListener ? el.addEventListener(type, fn, false) : el.attachEvent('on' + type, fn); } function $(id){ return document.getElementById(id); } var p1 = $('parent1'), p2 = $('parent2'); function fn(e){ var d = document.createElement('div'); d.innerHTML = e.type; $('result').appendChild(d); } on(p1,'mouseover',fn); on(p2,'mouseenter',fn); </script> <body> </html> 


[解决办法]
看看这个有帮助没

热点排行
Bad Request.