使用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');
}