zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    CSS3属性transform详解之(旋转:rotate,缩放:scale,倾斜:skew,移动:translate)
    MySQL<添加、更新与删除数据>
    MySQL<数据库和表的基本操作>
    MySQL<数据库入门>
    MySql阶段案例
    Mysql综合案例
    Mysql课后思考题
    Java课后思考题
    Java课后简答题
    超全面的JavaWeb笔记day23<AJAX>
  • 原文地址:https://www.cnblogs.com/colaman/p/6640750.html
Copyright © 2011-2022 走看看