<?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="???"/>
求解,如何点击按钮,刷新文本框的时间

解决方案 »

  1.   


    <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()"/>
      

  2.   

    好吧,谢谢的LSD,如果有用php的方法,请帖下代码
      

  3.   

    如果要页面不刷新的更新input的value属性值,那么只有用javascript,你要用php的话页面会刷新的
      

  4.   

    确实,局部刷新只能用javascript,用PHP的话整张页面都一起刷新了
      

  5.   

    要用php取时间 得用到 ajax 自己搜下
      

  6.   

    你想从php获取时间数据最好用ajax发送请求!
      

  7.   

    这种情况最好还是用JavaScript来做...
      

  8.   

    DateTime.Now.Tostring()简单 明了!!
      

  9.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <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
      

  10.   

    http://flyaway.oni.cc/fy/111.html可以在这看效果