我只有一个输入字段,我想注册onChange和onKeyPress事件来检测用户何时完成输入或按下Enter键。我需要仅使用JavaScript实现。谢谢帮助。
我有:
var load = function (){
//I want to trigger this function when user hit Enter key.
}
document.getElementById('co').onchange=load; //works great
document.getElementById('co').onKeyPress=load;
//not sure how to detect when user press Enter
HTML
//no form just a single input field
<input type='text' id='co'>