<input type="text" size="20" onclick="this.value=getDate()">
<script>
function getDate(){
now=new Date();
return now.toLocaleString();
}
</script>

解决方案 »

  1.   

    谢谢我已经试用了,我在script后面加上了language="javascript",但是出现的错误提示是:缺少对象“this”,怎么回事呢??
      

  2.   

    <html>
    <head>
    <script language="javascript">
    function getDate(my)
    {
    date= new Date();
    my.value=date.toLocaleString();
    }
    </script>
    </head>
    <body> 
    <form method="post">
    Let me try:<input type="text" name="entry" value=""  onClick="getDate(this);">
      </form>
      </body>
    </html>我用的是IE6.0
      

  3.   

    var newtime= new Date();
    my.value =newtime.getYear()+"."+(newtime.getMonth()+1)+"."+newtime.getDate()+" "+newtime.getHours()+":"+newtime.getMinutes()+":"+newtime.getSeconds();
      

  4.   

    <html>
    <head>
    <script language="javascript">
    function getDate(my)
    {
    var newtime= new Date();
    my.value =newtime.getYear()+"."+(newtime.getMonth()+1)+"."+newtime.getDate()+" "+newtime.getHours()+":"+newtime.getMinutes()+":"+newtime.getSeconds();
    }
    </script>
    </head>
    <body> 
    <form method="post">
    Let me try:<input type="text" name="entry" value=""  onClick="getDate(this);">
      </form>
      </body>
    </html>
      

  5.   

    谢谢我已经试用了,我在script后面加上了language="javascript",但是出现的错误提示是:缺少对象“this”,怎么回事呢??可能是浏览器版本问题。
      

  6.   

    <html>
    <head>
    <title>无标题文档</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="javascript">function cc()
    {
    var e = event.srcElement;
    var r =e.createTextRange();
    r.moveStart("character",e.value.length);
    r.collapse(true);
    r.select();
    }
    function getCurTime(){
        var pubyear,pubmonth,pubday,pubhour,pubmini;
        var Date1=new Date();
        pubyear=Date1.getYear();
        pubmonth=(Date1.getMonth()+1);
        pubday=Date1.getDate();
        pubhour=Date1.getHours();
        pubmini=Date1.getMinutes();    pubmonth=pubmonth<10?("0"+pubmonth):pubmonth;
        pubday=pubday<10?("0"+pubday):pubday;
        pubmini=pubmini<10?("0"+pubmini):pubmini;
        pubCurDate=pubyear+"-"+pubmonth+"-"+pubday;
        pubCurTime=pubCurDate+" "+pubhour+":"+pubmini;
    return pubCurTime;
    }
    function init(src){
    src.value=getCurTime();
    src.select();}
    function checkpress(src,e){
    if(event.keyCode==13){
    event.keyCode=9;
    }
    else return ;
    var strTime=pubCurDate+" "+pubhour+":"+"00"
    var val=src.value;
    var len=val.length;
    if(len<16){
    val=val+strTime.substring(len,16);
    src.value=val;
    }}function inputTM(src){
    var reg=/^\d{1,4}([-\/](\d{1,1}(\d{1,1}([-\/](\d{1,1}(\d{1,1}([ \/](\d{1,1}(\d{1,1}([:\/](\d{1,1}(\d{1,1})?)?)?)?)?)?)?)?)?)?)?)?$/ ;
    if(event.keyCode==8 || event.keyCode==46) return true
    var srcElem    = src
    var oSel    = document.selection.createRange()
    var srcRange    = srcElem.createTextRange()
    oSel.setEndPoint("StartToStart", srcRange)
    var strSplit=""
    switch((src.value).length)
    {
    case 4:
    case 7:
    strSplit="-";
    break;
    case 10:
    strSplit=" ";
    break;
    case 13:
    strSplit=":";
    break;
    default:
    break;
    }
    if(strSplit!="")
    {
    var num = src.value+strSplit
    if( reg.test(num))
    src.value=src.value+strSplit
    }}function regInputTM()
    {
    var reg= /^\d{1,4}([-\/](\d{1,1}(\d{1,1}([-\/](\d{1,1}(\d{1,1}([ \/](\d{1,1}(\d{1,1}([:\/](\d{1,1}(\d{1,1})?)?)?)?)?)?)?)?)?)?)?)?$/ ;
    if(event.keyCode==8 || event.keyCode==46) return true
    var srcElem    = event.srcElement
    var oSel    = document.selection.createRange()
    var srcRange    = srcElem.createTextRange()
    oSel.execCommand( "Cut")
    oSel.setEndPoint("StartToStart", srcRange)
    var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length)
    event.returnValue = reg.test(num)
    }
    </script></head>
    <BODY >
    <input type="text" name="txt" maxlength="16" onfocus="init(this)" onkeyup="inputTM(this)" onkeypress="regInputTM()" onkeydown="checkpress(this,event.keyCode)">
    <input type="text" name="txt" maxlength="16" onfocus="init(this)" onkeyup="inputTM(this)" onkeypress="regInputTM()" onkeydown="checkpress(this,event.keyCode)">
    <input type="text" name="txt" maxlength="16" onfocus="init(this)" onkeyup="inputTM(this)" onkeypress="regInputTM()" onkeydown="checkpress(this,event.keyCode)">
    <input type="text" name="txt" maxlength="16" onfocus="init(this)" onkeyup="inputTM(this)" onkeypress="regInputTM()" onkeydown="checkpress(this,event.keyCode)">
    <input type="text" name="txt" maxlength="16" onfocus="init(this)">
    </body>
    </html>