点击“Enter”键从textarea提交数据。 [英] Submitting data from textarea by hitting "Enter"
问题描述
[SomeTextarea] .onkeyup = function(e){
e = e ||事件;
if(e.keyCode === 13){
//开始提交函数
}
返回true;
}
*为什么不为此使用文本输入字段? Textarea特别适用于多行输入,单行输入的文本输入字段。使用输入处理程序,可以缩放多行输入。我记得曾经为XHR(aka AJAX)聊天应用程序使用它(因此textarea的行为类似于MSN输入区域),但使用CTRL输入键为新行重新启用多行输入。可能是你的想法?监听器将会像这样扩展:
pre $ [code> [SomeTextarea] .onkeyup = function(e){
e = e | |事件;
if(e.keyCode === 13&!e.ctrlKey){
//开始提交函数
}
返回true;
}
I have dynamic web page with JS. There is a textarea and a Send button, but no form tags. How do I make Submit button fire and the textarea get cleared when Enter is pressed in the textarea?
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;
}
这篇关于点击“Enter”键从textarea提交数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!