简体   繁体   English

将mousedown事件注册为Google图表的点击

[英]Registering mousedown event as click with google charts

I'm trying to send a mousedown event as a click to google charts although have hit a road block and not sure why im getting the following error. 我试图将mousedown事件作为点击发送给Google图表,尽管遇到了障碍,并且不确定为什么会收到以下错误。

I'm using jQuery and google charts api, visualisationOverlay is an absolute positioned div over the top of the chart, the error is when dispatchEvent sends the modified event to the google chart iframe. 我正在使用jQuery和google图表api,visualisationOverlay是图表顶部的绝对定位div,错误是当dispatchEvent将修改后的事件发送到google图表iframe时。

$('#visualizationOverlay').live('mousedown',function(e){
    e.type = "click";
    vis = document.getElementById($('#visualization').find('iframe').attr('id'));
    console.log(vis);
    vis.dispatchEvent(e);
});

I get the following error in firefox 我在Firefox中收到以下错误

NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMEventTarget.dispatchEvent]

Any hints where i'm going wrong would be highly appreciated! 我要去哪里的任何提示将不胜感激!

You can't trigger an event that was fired to another element. 您无法触发触发到另一个元素的事件。 You need to create a new event or just use jQuerys trigger . 您需要创建一个新事件或仅使用jQuerys trigger

Take a look at this example . 看一下这个例子 Click on the first element fires an error as the second log as expected. 单击第一个元素将引发错误,第二个日志将按预期方式发送。

$('#id1').on('mousedown', function(e){
  e.type = 'click';
  $('#id2').get(0).dispatchEvent(e);
});

$('#id2').on('mousedown', function(e){
  $('#id1').trigger('click')
});

$('#id1').on('mousedown', function(e){
  console.log('mousedown');
});

$('#id2').on('click', function(e){
  console.log('click');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM