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
andkeyHooks
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版本