popstate 返回 event.state 未定义
我正在学习 HTML5 中的历史记录,在此示例中(打开 JavaScript 浏览器控制台查看错误)event.state.url
返回:
Uncaught TypeError: Cannot read property 'url' of undefined
I am learning about history in HTML5, in this example (open the JavaScript browser console to see error) the event.state.url
returns:
Uncaught TypeError: Cannot read property 'url' of undefined
Look and help: http://jsfiddle.net/un4Xk/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
event
是 jQuery 事件对象,而不是 DOM 事件对象。要访问 DOM 事件对象,请使用
event.originalEvent
:http://jsfiddle .net/pimvdb/un4Xk/1/。请记住,仅当新状态有数据时才定义状态,因此单击然后返回初始状态时不可用:
但是,它是,单击时可用,再单击一次然后返回:
event
is the jQuery event object, not the DOM one.To access the DOM event object, use
event.originalEvent
: http://jsfiddle.net/pimvdb/un4Xk/1/.Remember that the state is only defined when the new state has data, so it is not available when clicking and then going back to the initial state:
It is, however, available when clicking, clicking another time and then going back: