作者:cshaadi_915 | 来源:互联网 | 2023-05-18 15:36
IwanttowriteaJavascripttestthatsimulatesakeypressontherightarrowkey.Hereismyattem
I want to write a Javascript test that simulates a keypress on the right arrow key. Here is my attempt to create the 'keydown' event:
我想编写一个模拟右箭头键上的按键的Javascript测试。这是我尝试创建'keydown'事件:
var data = {
key: 'ArrowRight'
};
var ev = new KeyboardEvent('keydown', data);
console.log(ev);
http://jsfiddle.net/lsiden/6e7duck6/
When I examine the output in the developer console, I expect to see the value 39 in one of the event fields, but it appears to remain uninitialized.
当我在开发者控制台中检查输出时,我希望在其中一个事件字段中看到值39,但它似乎仍然未初始化。
KeyboardEvent {which: 0, keyCode: 0, charCode: 0, repeat: false, metaKey: false…}
altKey: false
bubbles: false
cancelBubble: false
cancelable: false
charCode: 0
ctrlKey: false
currentTarget: null
defaultPrevented: false
detail: 0
eventPhase: 0
keyCode: 0
keyIdentifier: ""
keyLocation: 0
layerX: 0
layerY: 0
location: 0
metaKey: false
pageX: 0
pageY: 0
path: Array[0]
repeat: false
returnValue: true
shiftKey: false
srcElement: null
target: null
timeStamp: 1430931169397
type: "keydown"
view: null
which: 0
__proto__: KeyboardEvent
.
I tried to follow the docs: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent
我试着按照文档:https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent
Has anyone done this before?
有没有人这样做过?
2 个解决方案