Ari*_*ian 6 html javascript ajax
当光标使用Javascript进入输入文本字段时,如何发送键组合(如Ctrl + C或Alt + Shift)?
我没有使用jQuery,但使用的是MS-Ajax.是否可以使用MS-Ajax DOM?
编辑1)
根据@Ghostoy的帮助,我写了这段代码:
function simulateKeyPress() {
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, window,
0, 0, 0, 0,
0, "e".charCodeAt(0))
var canceled = !body.dispatchEvent(evt);
if (canceled) {
alert("canceled");
} else {
alert("not canceled");
}
}
Run Code Online (Sandbox Code Playgroud)
但是当它被调用时我得到一个错误:
Error: Object doesn't support property or method 'initKeyEvent'
Run Code Online (Sandbox Code Playgroud)
然后我改变了KeyboardEvent对KeyEvents我得到这个错误:
Error: DOM Exception: NOT_SUPPORTED_ERR (9)
Run Code Online (Sandbox Code Playgroud)
我的错在哪里?