可能重复:
Javascript捕获密钥
我正在使用mysql和php处理回复功能.
我的MySQL数据库:
reply:
rid - id;
topicid - under which topic;
uid - id of the guy who replies;
content - what did the guy said.
Run Code Online (Sandbox Code Playgroud)
这是我的HTML代码:
<form id="replyform">
<textarea name="rplcont" placeholder="Press enter to submit your reply."><textarea>
</form>
Run Code Online (Sandbox Code Playgroud)
我的问题是:我如何知道是否按下了输入按钮?
非常感谢.
/ ---------------------------------------------- /
这是我的代码有效:
HTML:
<textarea id="reply" name="reply" onKeyPress="enterpressalert(event, this)"></textarea>
Run Code Online (Sandbox Code Playgroud)
JS:
function enterpressalert(e, textarea){
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
alert('enter press');
}
}
Run Code Online (Sandbox Code Playgroud)
它的工作原理.
感谢关注此主题的所有人!
将字段与当前时间进行比较时遇到一些麻烦.
我在MySQL有两个字段,记录讲座的开始时间和结束时间.
我要做的是检查当前时间是否在开始时间和结束时间之间.
$ starttime和$ endtime采用DateTime的形式.
代码在这里:
$now = time();
$compare = mysql_query("SELECT * FROM lecture WHERE strtotime(starttime) < '$now' AND '$now' < strtotime(endtime)");
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
我也试过这个:
$now = new DateTime;
$compare = mysql_query("SELECT * FROM lecture WHERE starttime < '$now' AND '$now' < endtime");
Run Code Online (Sandbox Code Playgroud)
但它也破了.
谁能告诉我如何实现它?非常感谢.