jQuery 1.7 clientX/pageX 未定义

标签 jquery jquery-ui events jquery-1.7

我使用 jQuery 并从 jqueryUI 中拖动。当我将 jQuery 从 1.6 更新到 1.7 时,clientX 和 pageX 属性从事件变量中消失。这是一个例子:

http://jsbin.com/ezulas/7/edit

如果在给定示例中 jQuery 版本更改为 1.6.4 - 它就会开始工作。使用最新版本 - clientX/Y 和 pageX/Y 均无法正常工作。我发现我可以使用 e=e.originalEvent - 但这似乎不是正确的解决方案。

最佳答案

event.layerX and event.layerY: We have removed these non-standard properties in version 1.7. Although we normally would have gone through a deprecation notice period for these, Chrome version 16 generates a flood of console warning messages on the page. Because of this, we decided to remove them immediately. On platforms that still support these properties, they are available through event.originalEvent.layerX and event.originalEvent.layerY.

来源:http://blog.jquery.com/2011/11/03/jquery-1-7-released/

当您在 dragstop 事件处理程序中使用 console.log(e); 时,您可以看到所有 x/y jQuery 1.7 中缺少坐标数据;但可以在 event.originalEvent 中访问它。

更新

如果您查看 event 对象,您可以在 origionalEvent 属性中找到 pageX/pageY:

$('#test').html(e.originalEvent.pageX+','+e.originalEvent.pageY);

这是您的 jsbin 的更新版本:http://jsbin.com/ezulas/13/edit

关于jQuery 1.7 clientX/pageX 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8583249/

相关文章:

javascript - Rails 使用 'read more' 切换 chop

jQuery 数据表显示 html 内容

javascript - 视差 "scrolling"仅通过导航

jquery-ui - 页面加载时,jQuery UI 对话框出现在页面顶部

c++ - 为什么 WindowStateChange 事件对我不起作用

c# - MVVM 交替事件模式

javascript - 在运行时动态更改 setInterval 值

jquery - IE 中的 Colorbox(jQuery 图片库插件)问题

javascript - Rails jquery sortable 无法正确保存位置

javascript - contenteditable div 和子跨度上的 Keydown 事件