【发布时间】:2015-06-26 17:34:46
【问题描述】:
W3C specification 声明 initTouchEvent 如下:
void initTouchEvent (in DOMString type,
in boolean canBubble,
in boolean cancelable,
in AbstractView view,
in long detail,
in boolean ctrlKey,
in boolean altKey,
in boolean shiftKey,
in boolean metaKey,
in TouchList touches,
in TouchList targetTouches,
in TouchList changedTouches);
但是,当我在 Chrome 44 中尝试时:
var e = document.createEvent('TouchEvent');
e.initTouchEvent("touchstart", true, true, window, 1,
false, false, false, false, touches, null, null);
其中touches 是有效的TouchList,这是 Chrome 创建的:
> TouchEvent {}
altKey: false
bubbles: true
cancelBubble: false
cancelable: true
changedTouches: null
charCode: 0
ctrlKey: true
currentTarget: null
defaultPrevented: false
detail: 0
eventPhase: 0
keyCode: 0
layerX: 0
layerY: 0
metaKey: false
pageX: 0
pageY: 0
path: Array[0]
returnValue: true
shiftKey: false
srcElement: null
target: null
targetTouches: null
timeStamp: 1435339572699
touches: null
type: "[object Window]"
view: null
which: 0
仔细查看type 字段。似乎 Chrome 没有遵循将第 4 个参数转换为类型而不是第一个参数的规范。
这给我们带来了一个问题,即我如何在 Chrome 中实际创建一个 TouchEvent,因为它不符合规范?
【问题讨论】:
-
initTouchEvent()没有记录在 MDN 或(据我所知)W3C 上,因此很难找出这里实际发生的情况。 -
您是否尝试过使用 JQuery 或类似的东西?
-
它记录在 W3C 上(链接在问题中)。此外,jQuery 无法帮助我,因为 jQuery 调度“假”内部事件。
标签: javascript google-chrome touch dom-events