.click()和创建鼠标事件之间的区别? [英] Difference between .click() and creating a mouse event?

查看:129
本文介绍了.click()和创建鼠标事件之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想弄清楚



link.click()



  var event = document.createEvent(MouseEvents); 
event.initEvent(click,true,false);
link.dispatchEvent(event);

至于我可以告诉这些应该是一样的东西(然而使用我的jsfiddle a / c>

使用.click()与firefox弹出下载csv不会显示(将以chrome形式显示)



请参阅示例 - > http:// jsfiddle。 net / a5E9m / 23 /



在使用鼠标事件时,



- > http://jsfiddle.net/a5E9m/25/

解决方案

我认为Firefox对< a> 元素的点击函数有限制。请参见此处。而当你自己连接鼠标事件时,你是手动添加点击布线。另请参阅此处此处。 / p>

此外,如Boris Zbarsky在注释中指出的,< a> 元素没有点击功能在 规格


So I am trying to work out the differences between

link.click()

and

var event = document.createEvent("MouseEvents");
event.initEvent("click", true, false);
link.dispatchEvent(event);

As far as I can tell these should be the same things (however working with my jsfiddle example of exporting a csv from a URI this is not the case as they perform differently from browser to browser)

Using .click() with firefox the popup to download the csv will not show (it will in chrome)

see example -> http://jsfiddle.net/a5E9m/23/

Where as using the Mouse events it will

see example -> http://jsfiddle.net/a5E9m/25/

解决方案

I think that Firefox has restrictions around the click function on an <a> element. See here. Whereas when you wire up the mouse event yourself, you are manually adding the click wiring. Also, see here and here.

Also, as Boris Zbarsky pointed out in the comments, the <a> element does not have a click function on it in the spec.

这篇关于.click()和创建鼠标事件之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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