I want to retain the conventional 'form submits when i press Enter' behavior because users are familiar with. But by reflex, they often hit enter when they finish with a text input box - but before they are actually done with the complete form.
I'd like to hijack the Enter key only when then focus is on a certain class of input.
看Related Questions这看起来像我要找的:
if (document.addEventListener) {
document.getElementById('strip').addEventListener('keypress',HandleKeyPress,false);
} else {
document.getElementById('strip').onkeypress = HandleKeyPress;
}
but the if (document.addEventListener) {
part is unfamiliar to me.