<?php
function _time(){
date_default_timezone_set('Asia/Shanghai');
echo date("Y-m-d H:i:s");
}
?>
<input type="text" name="Addtime" id="Addtime" style="width:250px;height:20px;" readonly="readonly" value="<?php _time() ?>"/>
<input type="Button" name="Button" id="Button" value="当前时间" onClick="???"/>
求解,如何点击按钮,刷新文本框的时间
function _time(){
date_default_timezone_set('Asia/Shanghai');
echo date("Y-m-d H:i:s");
}
?>
<input type="text" name="Addtime" id="Addtime" style="width:250px;height:20px;" readonly="readonly" value="<?php _time() ?>"/>
<input type="Button" name="Button" id="Button" value="当前时间" onClick="???"/>
求解,如何点击按钮,刷新文本框的时间
<script language="javascript">
function getDateTime()
{
var date = new Date();
var thisYear = date.getYear();
var thisMonth = date.getMonth() + 1;
//如果月份长度是一位则前面补0
if(thisMonth<10) thisMonth = "0" + thisMonth;
var thisDay = date.getDate();
//如果天的长度是一位则前面补0
if(thisDay<10) thisDay = "0" + thisDay;
var thisHour = date.getHours();
//如果小时长度是一位则前面补0
if(thisHour<10) thisHour = "0" + thisHour;
var thisMinute = date.getMinutes();
//如果分钟长度是一位则前面补0
if(thisMinute<10) thisMinute = "0" + thisMinute;
var thisSecond = date.getSeconds();
//如果分钟长度是一位则前面补0
if(thisSecond<10) thisSecond = "0" + thisSecond;
document.getElementById("Addtime").value = thisYear + "-" + thisMonth + "-" + thisDay + " " + thisHour + ":" + thisMinute + ":" + thisSecond;}
</script>
<input type="text" name="Addtime" id="Addtime" style="width:250px;height:20px;" readonly="readonly" />
<input type="Button" name="Button" id="Button" value="当前时间" onClick="getDateTime()"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body><input type="text" name="Addtime" id="Addtime" style="width:250px;height:20px;" readonly="readonly" value=""/>
<input type="Button" name="Button" id="Button" value="当前时间" onClick="ajaxFunction()"/><script language="javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{ try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById("Addtime").value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","oo.php?oo"+Math.random(),true);
xmlHttp.send(null);
}</script>
</body>
</html>
这是html页面<?php
header('Content-Type:text/html;charset=GB2312');
function _time(){
date_default_timezone_set('Asia/Shanghai');
echo date("Y-m-d H:i:s");
}
_time();
?>
这是php的貌视只有用ajax,或者全js