input默认显示当前时间


 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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM