Tôi chỉ có 1 trường nhập và tôi muốn đăng ký sự kiện onChange và onKeyPress để phát hiện khi người dùng hoàn thành đầu vào của họ hoặc nhấn phím Enter. Tôi chỉ cần sử dụng javascript. Cảm ơn đã giúp đỡ.Cách phát hiện khi người dùng nhấn Enter trong trường nhập
tôi có:
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'>
có thể trùng lặp của [Nhập sự kiện nhấn phím trong JavaScript] (http://stackoverflow.com/questions/905222/enter-key-press-event-in -javascript) – Bae