如果你将"onkeydown"替换为"click",它至少会有反应。
<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>