jQuery.event.props未定义 [英] jQuery.event.props is undefined

查看:431
本文介绍了jQuery.event.props未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jquery.event.move 在触摸设备上创建移动事件. 该脚本在第580行上引发了错误.

I'm using jquery.event.move to create move events on touch devices. The script is throwing an error on line 580.

570 // Make jQuery copy touch event properties over to the jQuery event
571 // object, if they are not already listed. But only do the ones we
572 // really need. IE7/8 do not have Array#indexOf(), but nor do they
573 // have touch events, so let's assume we can ignore them.
574 if (typeof Array.prototype.indexOf === 'function') {
575     (function(jQuery, undefined){
576         var props = ["changedTouches", "targetTouches"],
577             l = props.length;
578         
579         while (l--) {
580             if (jQuery.event.props.indexOf(props[l]) === -1) {
581                 jQuery.event.props.push(props[l]);
582             }
583         }
584     })(jQuery);
585 };

到达580行时抛出Uncaught TypeError: Cannot read property 'indexOf' of undefined 我了解的方式是jQuery.event.props是未定义的?默认情况下,jquery中不应该存在此数组吗? 我已经将jquery作为宝石安装"在我的rails应用程序中(jquery-rails 4.1.1) 知道我能做什么吗?

When it gets to line 580 it throws Uncaught TypeError: Cannot read property 'indexOf' of undefined The way I understand it is that jQuery.event.props is undefined? Shouldn't this array be present by default in jquery? I've "installed" jQuery in my rails app as a gem (jquery-rails 4.1.1) Any idea what I could do?

推荐答案

jquery版本3或更高版本存在问题,如 issue 页面:

There is an issue with jquery version 3 or above as mentioned in the jquery.event.move github issue page:

jQuery 3.0.0中断了jQuery.event.props的使用

这是因为在jQuery 3.0.0升级中删除了jQuery.event.propsjQuery.event.fixHooks.这里有更多详细信息:

This happened since in jQuery 3.0.0 upgrade jQuery.event.props and jQuery.event.fixHooks are removed. More details here:

重大更改:已删除jQuery.event.propsjQuery.event.fixHooks

jQuery的事件处理性能有所提高,这要归功于 重组活动财产管理.主要的改进是 jQuery现在只计算或复制第一个属性 访问,而不是预先计算和复制它们.这是一个 可能会迫使事件布局的属性获得了巨大的胜利 处理程序甚至可能不需要.我们知道的最常见的用途是添加 指针事件的属性,不再需要,因为 jQuery 3.0已支持这些事件. jQuery迁移 如果您仍然需要这些属性,则插件会为其提供支持. 相关但未记录的mouseHookskeyHooks列表是 以及删除.团队有兴趣了解其他用途 在定义新的API之前,请随时打开票证.

jQuery's event handling performance increased thanks to a reorganization of event property management. The main improvement is that jQuery now only calculates or copies a property on the first access, rather than calculating and copying them up front. This is a really big win with properties that may force layout that the event handler may not even need. The most common use we know of was to add properties for pointer events, which is no longer necessary because those events are supported already in jQuery 3.0. The jQuery Migrate plugin provides support for these properties if you still need them. The related but undocumented mouseHooks and keyHooks lists were removed as well. The team is interested in understanding other use cases before defining new APIs, so feel free to open a ticket.

github问题仍未解决,截至2016年1月8日尚未提供解决方案.作为替代解决方案,您可以:-

The github issue is still open and no solution has been provided yet as of 08.01.2016. As an alternative fix you can either:-

  • 使用jQuery Migrate插件,该插件为这些插件提供支持 特性.
  • 或者,使用3.0.0以下的任何jQuery版本
  • Use the jQuery Migrate plugin, which provides support for these properties.
  • Or, use any jQuery version below 3.0.0

这篇关于jQuery.event.props未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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