<input type="hidden" name="shijian" id="shijian" style="width:250px" class="intxt" value="">我这里的表单如何获取当前js获取的时间<script language="JavaScript"> 
function getDate()
{
var today = new Date(); 
 var date; 
date = (today.getFullYear()) +"年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日-" + today.toLocaleTimeString();  
return date;
}
</script> 

解决方案 »

  1.   

    只能通过js传入表单中,而表单自己是不能获取到的。document.getElementById('shijian').value = getDate();
      

  2.   

    <input type="hidden" name="shijian" id="shijian" style="width:250px" class="intxt" value="">
    <script language="JavaScript"> 
    function getDate()
    {
    var today = new Date(); 
     var date; 
    date = (today.getFullYear()) +"年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日-" + today.toLocaleTimeString();  
    return date;
    }
    window.onload = function(){
    document.getElementById('shijian').value = getDate();
    };
    </script> 
      

  3.   

    <!DOCTYPE html>
    <html>
        <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title>Test</title>
        </head>
        <body>
         <form>
         <input type="text" id="shijian" style="width:250px" value="" />
         </form>
        <script>
    function getDate(){
    var today = new Date(); 
    var date; 
    date = (today.getFullYear()) +"年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日-" + today.toLocaleTimeString();  
    return date;
    }
    window.onload = function(){
    var input = document.getElementById("shijian");
    setInterval(function(){
    input.value = getDate();
    }, 1000);
    }
        </script>
        </body>
    </html>