jQuery.event.props 未定义

2024-01-10

我在用着jquery.event.move https://github.com/stephband/jquery.event.move在触摸设备上创建移动事件。 该脚本在第 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 中吗? 我已经在我的 Rails 应用程序中“安装”了 jQuery 作为 gem (jquery-rails 4.1.1) 知道我能做什么吗?


jquery 版本 3 或更高版本存在问题,如jquery.event.move https://github.com/stephband/jquery.event.move github issue https://github.com/stephband/jquery.event.move/issues page:

jQuery 3.0.0 中断jQuery.event.props usage https://github.com/stephband/jquery.event.move/issues/31

自从 jQuery 3.0.0 升级以来就发生了这种情况jQuery.event.props and jQuery.event.fixHooks被删除。更多详细信息请参见此处:

重大变化:jQuery.event.props and jQuery.event.fixHooks removed https://jquery.com/upgrade-guide/3.0/#breaking-change-jquery-event-props-and-jquery-event-fixhooks-removed

jQuery 的事件处理性能的提高得益于 重组活动物业管理。主要改进是 jQuery 现在只计算或复制第一个属性 访问,而不是预先计算和复制它们。这是一个 真正的巨大胜利,其属性可能会迫使事件的布局 处理程序可能甚至不需要。我们知道的最常见的用途是添加 指针事件的属性,不再需要,因为 jQuery 3.0 已支持这些事件。 jQuery 迁移 如果您仍然需要这些属性,插件会提供对它们的支持。 相关但未记录的mouseHooks and keyHooks名单是 也删除了。该团队有兴趣了解其他用途 定义新 API 之前的案例,因此请随时开票。

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

  • 使用 jQuery Migrate 插件,它为这些提供支持 特性。
  • 或者,使用 3.0.0 以下的任何 jQuery 版本
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jQuery.event.props 未定义 的相关文章

随机推荐