zoukankan      html  css  js  c++  java
  • input框中自动展示当前日期 yyyy/mm/dd

    直接上代码:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <title>input框中自动展示当前日期</title>
    </head>
    
    <body>
        <input type="text" id="input">
        <script>
        //获取input元素
        var _input = document.getElementById('input');
    
        var date = new Date();
        var seperator = "/";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentDate = year + seperator + month + seperator + strDate; //当前日期
    
        _input.value = currentDate; //赋值给input.value
        _input.setAttribute('disabled', 'disabled'); //不可编辑
        </script>
    </body>
    
    </html>

    这里注意,getMonth()方法,使用本地时间。返回值是 0(一月) 到 11(十二月) 之间的一个整数。

  • 相关阅读:
    dpdk优化相关 转
    常用的TCP Option
    c10k C10M
    Linux惊群效应详解
    bloomfilter 以及count min sketch
    Squid 搭建正向代理服务器
    Openflow的架构+源码剖析 转载
    Hyperscan与Snort的集成方案
    动态图
    psutil 模块
  • 原文地址:https://www.cnblogs.com/iceflorence/p/7123503.html
Copyright © 2011-2022 走看看