PJax在jQuery 3.0无法运行问题修复

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PJax在jQuery 3.0无法运行问题修复相关的知识,希望对你有一定的参考价值。

PJax在jQuery 3.0无法运行

【现象】

页面报错:Uncaught TypeError: Cannot read property ‘push‘ of undefined

【原因】

jQuery3.0开始去除了$.event.props

Breaking change: jQuery.event.props and jQuery.event.fixHooks removed

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.

 【修改】

方法一:用addProp代替 props.push。

if ( $.event.props && $.inArray(‘state‘, $.event.props) < 0 ) {
  $.event.props.push(‘state‘);
} else if ( ! (‘state‘ in $.Event.prototype) ) {
  $.event.addProp(‘state‘);
}

方法二:使用jQuery 3.0 的migrate版本

 

参见GitHub,PJax官网 issue 634.

 

以上是关于PJax在jQuery 3.0无法运行问题修复的主要内容,如果未能解决你的问题,请参考以下文章

pjax简单实例

emlog通过pjax实现无刷新加载网页--完美解决cnzz统计和javascript失效问题

jquery.pjax.js 应该怎么用?

pjax学习

PJAX全局无刷新的设置方法~

jquery.pjax 单页面, 无刷新打开页面.