【问题标题】:Detect enter key pressed using javascript [duplicate]检测使用javascript按下的输入键[重复]
【发布时间】:2012-12-24 11:19:15
【问题描述】:

可能重复:
Javascript capture key

我正在使用 mysql 和 php 开发回复功能。

我的 MySQL 数据库:

reply:
  rid - id;
  topicid - under which topic;
  uid - id of the guy who replies;
  content - what did the guy said.

这是我的 html 代码:

<form id="replyform">
  <textarea name="rplcont" placeholder="Press enter to submit your reply."><textarea>
</form>

我的问题是:我怎么知道是否按下了输入按钮?

非常感谢。

/------------------------------------------ ---/

这是我的有效代码:

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

它有效。

感谢所有关注这个话题的人!

【问题讨论】:

标签: javascript enter


【解决方案1】:
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
    alert('enter press');
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-16
  • 1970-01-01
  • 2018-12-09
  • 2011-11-11
  • 2013-01-04
  • 1970-01-01
相关资源
最近更新 更多