V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
shw1395
V2EX  ›  JavaScript

怎么让 input 显示一周后时间

  •  
  •   shw1395 · 2017-03-30 22:56:36 +08:00 · 2052 次点击
    这是一个创建于 2793 天前的主题,其中的信息可能已经有所发展或是发生改变。
    <input type="text" name="" id="" value="">

    <script type="text/javascript">
    /*
    [Discuz!] (C)2001-2099 Comsenz Inc.
    This is NOT a freeware, use is subject to license terms

    $Id: common_extra.js 35188 2015-01-19 04:22:32Z nemohou $
    */


    function _showselect(obj, inpid, t, rettype) {
    var showselect_row = function (inpid, s, v, notime, rettype) {
    if(v >= 0) {
    if(!rettype) {
    var notime = !notime ? 0 : 1;
    var t = today.getTime();
    t += 86400000 * v;
    var d = new Date();
    d.setTime(t);
    var month = d.getMonth() + 1;
    month = month < 10 ? '0' + month : month;
    var day = d.getDate();
    day = day < 10 ? '0' + day : day;
    var hour = d.getHours();
    hour = hour < 10 ? '0' + hour : hour;
    var minute = d.getMinutes();
    minute = minute < 10 ? '0' + minute : minute;
    return '<a href="javascript:;" onclick="$(\'' + inpid + '\').value = \'' + d.getFullYear() + '-' + month + '-' + day + (!notime ? ' ' + hour + ':' + minute: '') + '\'">' + s + '</a>';
    } else {
    return '<a href="javascript:;" onclick="$(\'' + inpid + '\').value = \'' + v + '\'">' + s + '</a>';
    }
    } else if(v == -1) {
    return '<a href="javascript:;" onclick="$(\'' + inpid + '\').focus()">' + s + '</a>';
    } else if(v == -2) {
    return '<a href="javascript:;" onclick="$(\'' + inpid + '\'). onclick()">' + s + '</a>';
    }
    };

    if(!obj.id) {
    var t = !t ? 0 : t;
    var rettype = !rettype ? 0 : rettype;
    obj.id = 'calendarexp_' + Math.random();
    div = document.createElement('div');
    div.id = obj.id + '_menu';
    div.style.display = 'none';
    div.className = 'p_pop';
    $('append_parent').appendChild(div);
    s = '';
    if(!t) {
    s += showselect_row(inpid, '一天', 1, 0, rettype);
    s += showselect_row(inpid, '一周', 7, 0, rettype);
    s += showselect_row(inpid, '一个月', 30, 0, rettype);
    s += showselect_row(inpid, '三个月', 90, 0, rettype);
    s += showselect_row(inpid, '自定义', -2);
    } else {
    if($(t)) {
    var lis = $(t).getElementsByTagName('LI');
    for(i = 0;i < lis.length;i++) {
    s += '<a href="javascript:;" onclick="$(\'' + inpid + '\').value = this.innerHTML;$(\''+obj.id+'_menu\').style.display=\'none\'">' + lis[i].innerHTML + '</a>';
    }
    s += showselect_row(inpid, '自定义', -1);
    } else {
    s += '<a href="javascript:;" onclick="$(\'' + inpid + '\').value = \'0\'">永久</a>';
    s += showselect_row(inpid, '7 天', 7, 1, rettype);
    s += showselect_row(inpid, '14 天', 14, 1, rettype);
    s += showselect_row(inpid, '一个月', 30, 1, rettype);
    s += showselect_row(inpid, '三个月', 90, 1, rettype);
    s += showselect_row(inpid, '半年', 182, 1, rettype);
    s += showselect_row(inpid, '一年', 365, 1, rettype);
    s += showselect_row(inpid, '自定义', -1);
    }
    }
    $(div.id).innerHTML = s;
    }
    showMenu({'ctrlid':obj.id,'evt':'click'});
    if(BROWSER.ie && BROWSER.ie < 7) {
    doane(event);
    }
    }

    </script>
    1 条回复    2017-04-06 17:26:36 +08:00
    flowfire
        1
    flowfire  
       2017-04-06 17:26:36 +08:00 via iPhone
    new Date().getTime() += 1000*3600*24*7;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1157 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 23:04 · PVG 07:04 · LAX 15:04 · JFK 18:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.