14
如果用「click」替換「onkeydown」,它至少會起作用。Javascript:帶onkeydown的addEventListener似乎不起作用
<input id="yourinput" type="text" />
<script type="text/javascript">
document.getElementById("yourinput").addEventListener("onkeydown", keyDownTextField, false);
function keyDownTextField() {
alert("functional");
if(keycode==13) {
alert("You hit the enter key.");
}
else{
alert("Oh no you didn't.");
}
}
</script>