event.originalEvent jQuery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16674963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:34:03  来源:igfitidea点击:

event.originalEvent jQuery

jqueryeventstouch

提问by BryanK

I am currently immersed in the jQuery learning center. I'm going from start to end.

我目前沉浸在 jQuery 学习中心。我从头到尾。

I just read this paragraph:

我刚读了这一段

It's also important to note that the event object contains a property called originalEvent, which is the event object that the browser itself created. jQuery wraps this native event object with some useful methods and properties, but in some instances, you'll need to access the original event via event.originalEventfor instance. This is especially useful for touch events on mobile devices and tablets.

同样重要的是要注意事件对象包含一个名为 的属性originalEvent,它是浏览器本身创建的事件对象。jQuery 使用一些有用的方法和属性包装这个原生事件对象,但在某些情况下,您需要通过event.originalEvent例如访问原始事件。这对于移动设备和平板电脑上的触摸事件特别有用。

The last sentence, 'This is especially useful for touch events on mobile devices and tablets.', really sparked my interest. but this is as much as the learning center goes into originalEventthus far.

最后一句,“这对于移动设备和平板电脑上的触摸事件特别有用。” ,真的引起了我的兴趣。但这与学习中心originalEvent迄今为止所涉及的一样多。

Does anyone know of good resources for a more intensive study/practice for event.originalEventspecifically in relation to touch events/mobile devices?

有没有人知道event.originalEvent专门针对触摸事件/移动设备进行更深入研究/实践的好资源?

回答by Travis J

event.originalEventis usually just the native event(also described here).

event.originalEvent通常只是本地人event(也在这里描述)。

However, if the browser is compatible, and the event was a touch eventthen that API will be exposed through event.originalEvent.

但是,如果浏览器兼容,并且事件是 ,touch event那么该 API 将通过event.originalEvent.

The short answer is that event.originalEventis not always the same, it depends on which event type triggered the handler, and on the environment of the browser.

简短的回答是event.originalEvent并不总是相同的,这取决于触发处理程序的事件类型以及浏览器的环境。

回答by Mohyaddin Alaoddin

I have a case which I needed to use event.originalEventthe problem was trying to get an instance of a dropped file via drag and drop using the drop event, this is what happened

我有一个案例,我需要使用event.originalEvent问题是尝试使用 drop 事件通过拖放来获取已放置文件的实例,这就是发生的事情

var files = event.dataTransfer.files; // Gives error: trying to get property of undefined

var files = event.dataTransfer.files; // Gives error: trying to get property of undefined

while writing

写作时

var files = event.originalEvent.dataTransfer.files; // Works fine

var files = event.originalEvent.dataTransfer.files; // Works fine

That means jQuery doesn't wrap the native browser event with all its APIs like the File API in this example, so to get access to those excluded properties and functions from the jQuery event we must use event.originalEvent. Hope that helps someone.

这意味着 jQuery 不会像本例中的 File API 那样用它的所有 API 包装原生浏览器事件,因此要从 jQuery 事件中访问那些排除的属性和函数,我们必须使用event.originalEvent. 希望能帮助某人。

回答by Nereo Costacurta

jQuery knows standard events and conforms them for different browsers. but when there's no standard event jQuery fails to conform the event object but has a failsafe originalEventthat keeps the original served object by the browser.

jQuery 知道标准事件,并针对不同的浏览器使它们一致。但是当没有标准事件时,jQuery 无法符合事件对象,但有一个故障保护originalEvent,可以保持浏览器提供的原始对象。

for example mousewheeland DOMMouseScrollneed event.originalEventtoo, since there is no support for wheel event.

例如mousewheel,也DOMMouseScroll需要event.originalEvent,因为不支持轮事件。