我正在尝试模拟Enter键。我尝试这样做似乎没有发生任何事情:
https://jsfiddle.net/jn4zy1fc/4/
<form>
<input type="text" id="field" onkeydown="test(event);">
</form>
<script>
function test(ev){
if(ev.keyCode == 13){
alert ("enter key");
}
}
field = document.getElementById("field");
var e = document.createEvent("KeyboardEvent");
e.initKeyboardEvent("keydown", true, true, window,true, false, false, false,13, 0);
field.dispatchEvent(e);
</script>