You could use an keyup handler for the textarea (although I would advise against it*).
[SomeTextarea].onkeyup = function(e){
e = e || event;
if (e.keyCode === 13) {
// start your submit function
}
return true;
}
*Why not use a text input field for this? Textarea is escpecially suited for multiline input, a text input field for single line input. With an enter handler you criple the multiline input. I remember using it once for a XHR (aka AJAX) chat application (so the textarea behaved like an MSN input area), but re-enabled multiline input using the CTRL-enter key for new lines. May be that's an idea for you? The listener would be extended like this:
[SomeTextarea].onkeyup = function(e){
e = e || event;
if (e.keyCode === 13 && !e.ctrlKey) {
// start your submit function
}
return true;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…