- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图理解为什么changedTouches不是事件的可测试属性。例如,如果我监听 touchstart 事件(通过 Chrome->检查并模拟移动设备),例如
$(document).on('touchstart', function(event){
console.log(event.hasOwnProperty('originalEvent')) //logs true
正如预期的那样。
现在,如果我记录整个事件,我可以清楚地看到它有 originalEvent.changedTouches 但测试该属性将失败
console.log(event.originalEvent.hasOwnProperty('changedTouches')) //logs false
但是我可以通过执行
列出 changedTouches console.log(event.originalEvent.changedTouches);
/*
logs:
hangedTouches: TouchList(1)
0: Touch { identifier: 0, screenX: 753, screenY: 746, … }
length: 1
*/
我还可以测试这两个属性都是对象
console.log(typeof(event.originalEvent), typeof(event.originalEvent.changedTouches)); //logs object object
问题是,为什么我不能使用 hasOwnProperty 测试此属性?
最佳答案
来自MDN :
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it).
尝试:
console.log('changedTouches' in event.originalEvent)
关于javascript - 更改触摸 :TouchList is not a property?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50883574/
我试图理解为什么changedTouches不是事件的可测试属性。例如,如果我监听 touchstart 事件(通过 Chrome->检查并模拟移动设备),例如 $(document).on('to
我遇到了一个很奇怪的问题。我将 touchstart 事件绑定(bind)到一个元素,并想检索该事件的 X 和 Y 坐标。全部documentation在线表示可通过以下方式之一获得: e.touch
我已经使用 Java 以外的语言进行了 10 多年的开发。我是 Android 世界的新手,但我正在尝试直接进入。我正在尝试制作一个可拖动的列表,我发现了很棒的 repo https://github
我正在尝试修改 TouchListView 组件以允许我将项目从 ListView 拖到另一个 View 上,以创建拖放选择系统。用户将拖动一个列表项并释放它以指示选择。 到目前为止,我已经修改了 D
我正在尝试将 cwac-touchlist 用作 Eclipse 中的项目库: https://github.com/commonsguy/cwac-touchlist 一切似乎都工作正常,除了我正在
我是一名优秀的程序员,十分优秀!