我怎样才能提交输入按下,而我amm键入textarea ........如果我打入输入它只打破了一条线,但不提交表格。从textarea提交表格
0
A
回答
5
尝试<textarea onkeypress="handleKeyEvent(event);">
function handleKeyEvent(e) {
var charCode;
if (e && e.which) {
charCode = e.which;
} else if (window.event) {
e = window.event;
charCode = e.keyCode;
}
if (charCode == 13) {
document.getElementById("yourForm").submit();
}
}
但是我建议不要这样的事情,或者至少确保用户知道按下回车键后会发生什么。通常他们期望换行。
+0
+1不这样做。 – ceejayoz 2009-12-21 18:02:55
1
您需要使用JavaScript。粗略地说:
- 戴上
textarea
- 在事件处理程序的
onkeypress
事件处理程序,check whether the key that was pressed is enter - 如果是这样,调用窗体的
submit
功能
另外,使用<input type="text">
代替<textarea>
。
0
从http://jennifermadden.com/javascript/stringEnterKeyDetector.html
使用JavaScript函数:
function checkEnter(e) {
//if which property of event object is supported (NN4)
if(e && e.which) {
//character code is contained in NN4's which property
characterCode = e.which;
}
else {
e = event;
//character code is contained in IE's keyCode property
characterCode = e.keyCode;
}
//if generated character code is equal to ascii 13 (if enter key)
if(characterCode == 13) {
//submit the form
document.forms[0].submit();
return false;
}
else {
return true;
}
}
然后使用您的textarea以下几点:
<textarea onKeyPress="checkEnter(event)">
相关问题
- 1. MethodNotAllowedHttpException从表单提交方程格式textarea(ckeditor)
- 2. 提交表格
- 3. 提交表格
- 4. 提交表格
- 5. 表格+表格不提交
- 6. 从textarea提交修剪空白行
- 7. 表格Textarea数据不能被替换提交
- 8. 如何在点击textarea时提交表格
- 9. 使用textarea onkeypress jQuery提交表格输入
- 10. 提交表单时,无法替换值textarea中的空格
- 11. jquery表单提交和textarea刷新
- 12. select2 - 提交表格
- 13. Python提交表格
- 14. PhantomJS:提交表格
- 15. preventDefault()提交表格
- 16. html表格提交
- 17. 表格提交Mootools
- 18. 表格不提交
- 19. Codeigniter提交表格
- 20. jQuery提交表格
- 21. 提交Jade表格
- 22. jEditable - 提交表格
- 23. Boxy提交表格
- 24. PHP表格提交
- 25. 未提交表格
- 26. Codeigniter:提交表格
- 27. Jquery提交表格
- 28. 提交dbgeography表格
- 29. Node.js - 提交表格
- 30. 提交后提交表格(Ruby on Rails)
这在技术上是意想不到的行为。当他们按下textarea中的输入时,人们希望看到一个线路回报。我鼓励你重新考虑你在做什么。 – Sampson 2009-12-21 17:40:43
同意乔纳森,但是,如果他们按Ctrl + Enter或其他修饰符,则可以提交表单。 Outlook只会发送电子邮件,第一次使用该快捷方式时会提醒您。 – 2009-12-21 19:26:33