1 方法一: 2 // 獲取當天的年月日 3 new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate(); 4 5 <form name="form1"> 6 7 <input type="text" name="test"> 8 </form> 9 <script language="JavaScript"> 10 today=new Date(); 11 form1.test.value=today.getYear()+'年'+today.getMonth()+'月'+today.getDay()+'日'; 12 </script> 13 14 <br> 15 16 方法二: 17 18 --------------------------------------------------------------- 19 20 <input TYPE="text" id="myDate"> 21 <script langguage="JavaScript"> 22 <!-- 23 var now = new Date(); 24 myDate.value=new Date().getFullYear() + '-' + (new Date().getMonth() + 1) + '-' + new Date().getDate(); 25 //--> 26 </script> 27 28 <br> 29 30 方法三: 31 32 --------------------------------------------------------------- 33 34 <script language="JavaScript"> 35 function time_rota() //寫當前日期的函數 36 { 37 var now = new Date(); 38 var h = now.getFullYear(); 39 var m = (now.getMonth() + 1>9) ? now.getMonth() + 1 : "0"+(now.getMonth() + 1); 40 var s = (now.getDate()>9) ? now.getDate() : "0"+now.getDate(); 41 document.form1.Today.value = h+"年"+m+"月"+s+"日"; 42 } 43 </script> 44 <body onload="time_rota()"> 45 46 <form name=form1> 47 <input name=Today> 48 </form>