使用javascript检测输入键 [英] Detect enter key pressed using javascript
本文介绍了使用javascript检测输入键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
Javascript捕获密钥
我正在使用mysql和php处理回复功能。
I'm working on reply function using mysql and php.
我的MySQL数据库:
My MySQL db:
reply:
rid - id;
topicid - under which topic;
uid - id of the guy who replies;
content - what did the guy said.
这是我的html代码:
Here's my html code:
<form id="replyform">
<textarea name="rplcont" placeholder="Press enter to submit your reply."><textarea>
</form>
我的问题是:我如何知道是否按下了输入按钮?
My question is: How do I know if enter button is pressed?
非常感谢。
/ ------------- --------------------------------- /
这是我的代码有效:
html:
<textarea id="reply" name="reply" onKeyPress="enterpressalert(event, this)"></textarea>
js:
function enterpressalert(e, textarea){
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
alert('enter press');
}
}
并且有效。
感谢所有关注此主题的人!
Thanks for everyone who concerns this topic!
推荐答案
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
alert('enter press');
}
这篇关于使用javascript检测输入键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文