Javascript:从对象中移除所有的mouseover事件 [英] Javascript: remove all mouseover events from an object

查看:126
本文介绍了Javascript:从对象中移除所有的mouseover事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题询问了Google图表,但更一般。

图表中的图例的鼠标悬停产生了此错误: $ b


未捕获TypeError:无法读取属性'x'为空


我没有添加任何'onmouseover'事件等等,它似乎只是对 null 在系列中的外观感到不满(当你绘制两个系列具有不同的x值,谷歌图表表示将空点添加为 null ,并用 interpolateNull:true )绘图。

有没有其他人有这个问题?有没有办法禁用图表图例的任何鼠标悬停事件?



非常感谢您提供的任何建议。

更新: 有一个最小的jsfiddle在这里展示这个错误。看起来Google图表不喜欢让两个x和y点具有完全相同的值。 您可以尝试停止适当的鼠标事件到达内置的处理程序。

这需要在图表的图例中添加一个 mouseover 侦听器。
监听器会调用 event.stopPropagation()(并且在 capture

事实上, mousemove 事件也正在被侦听,所以停止他们也是。



以下方法适用于Firefox:

  $(' svg> g:first-of-type')。bind('mouseover mousemove',function(e){e.stopPropagation();}); 


This question asks about Google charts, but is more general.

Mouseover of the legend in my chart gives this error:

Uncaught TypeError: Cannot read property 'x' of null

I haven't added any 'onmouseover' events, etc., it appears that it's just unhappy with the appearance of null in the series (when you plot two series with different x-values, Google charts says to add empty points as null and plot with interpolateNull : true).

Has anyone else had this problem? Is there a way to disable any mouseover events for the chart legend?

Thanks a lot for any advice you can give.

Update: There is a minimal jsfiddle demonstrating this error here. It seems Google charts doesn't like having two x and y points that have the exact same values.

解决方案

You could try stopping appropriate mouse events from reaching the built-in handlers.

This requires adding a mouseover listener to the chart's legend. The listener will call event.stopPropagation() (and surprisingly doesn't need to be triggered during the capture phase of event propagation).

It turns out that mousemove events are also being listened to, so stop them too.

The following worked for me on Firefox:

$('svg > g:first-of-type').bind('mouseover mousemove', function(e) { e.stopPropagation(); });

这篇关于Javascript:从对象中移除所有的mouseover事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆