可能重复:
Javascript 捕获键
我正在使用 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');
}
}
它有效。
感谢所有关注这个话题的人!