双击使用IE浏览器
我在IE中发现了双击问题。
以下是我的HTML:
Hello World!
而我的jQuery:
$('#test').bind('dblclick', function (event) { event.stopPropagation(); $(this).css({'background-color': 'red'}); });
在IE中,执行以下操作:
- 在DIV外面 ,鼠标按下→鼠标向上→鼠标按下→按住鼠标。
- 然后,按住鼠标,将鼠标移动到DIV并向上鼠标。
DIV变为红色,就好像双击事件起源于DIV。
似乎在IE中,双击时双击事件都被触发:
- DIV中的起点和终点
- 在DIV内部和DIV内部结束。
然而在FF / Chrome中,只有在DIV内双击STARTS和ENDS时才会触发该事件。
对此有何正式解释? 我怎样才能让IE双击表现得像FF / Chrome双击?
(上)dblclick事件是本机javascript事件,而不是jquery的事件
Dblclick事件在浏览器中不一致,看到这张票3年但仍以某种方式有效: http : //bugs.jquery.com/ticket/7876即使现在在IE10中的序列与FF / Chrome / Safari相同但是作为你注意到了,还有一些错误。
作为解决方法,您可以使用此代码段而不是dblclick事件:
DEMO与自定义dblclick
$('#test').on('click', function(event){ var t = this; if (!t.clicks) t.clicks = 0; ++t.clicks; if (t.clicks === 2) { t.clicks = 0; //here the kind of dclclick is fired ... $(t).css({'background-color' : "red"}); } setTimeout(function () { t.clicks = 0 }, 500);//duration value can be change depending of your wishes });
另一种解决方法可能是在mousedown / mouseenter / mouseleave(hover)处理程序上绑定/取消绑定dblclick事件,如下所示:
带有mousedown / mouseenter / mouseleave的演示
$('#test').hover(function () { $(this).on('mousedown.cust', function () { $(this).on('dblclick.cust', function () { $(this).css({ 'background-color': "red" }); }); }); }, function () { $(this).off('mousedown.cust dblclick.cust'); });
这是一个小提琴 。 jQuery的dblclick
适用于FF和IE9。 测试:“只有在DIV内双击STARTS和ENDS时才会触发事件”
$("#test").dblclick(function(event) { event.stopPropagation(); $(this).css({'background-color': 'red'}); });
- 使用jquery加载图像:IE9中的附加请求
- jQuery跨域请求仍然在IE中失败,但使用jsonp
- 尝试使用jQuery Columnizr插件:“Object不支持属性>或方法’columnize’”
- 当Internet Explorer开发人员工具栏可见时,JavaScript脚本仅适用于Internet Explorer
- VLC ActivX插件不在更新IE9中播放video
- IE9 – 函数错误:’ArrayBuffer’未定义ReferenceError:’ArrayBuffer’未定义
- 如果由jQuery设置,CSS3 2D变换不能在IE9上工作
- ASP.NET WEBAPI文件上传,IE9问题
- 为什么这个jQuery Ajax调用仅在IE9中失败(即使在IE8和IE7中工作正常)