douyou9923 2016-12-29 04:46
浏览 55
已采纳

在今天的datepicker后2天禁用

I want to disable 2 days after today with jquery datepicker, for example today is 12/29/2016 I want the enable date from 1/1/2017. I look the someone code in jsfiddle but I don't know what should I edit https://jsfiddle.net/AcbUf/574/

Html

<input type="text" id="from" />
<input type="text" id="to" />

Js

$(document).ready(function () {
var d = new Date();
var monthNames = ["January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December"];
today = monthNames[d.getMonth()] + ' ' + d.getDate() + ' ' + d.getFullYear();

$('#to').attr('disabled', 'disabled');
$('#from').datepicker({
    defaultDate: "+3d",
    minDate: 1,
    maxDate: "+3M",
    dateFormat: 'dd M yy',
    showOtherMonths: true,
    changeMonth: true,
    selectOtherMonths: true,
    required: true,
    showOn: "focus",
    numberOfMonths: 1,
});

$('#from').change(function () {
    var from = $('#from').datepicker('getDate');
    var date_diff = Math.ceil((from.getTime() - Date.parse(today)) / 86400000);
    var maxDate_d = date_diff+7+'d';
    date_diff = date_diff + 'd';
    $('#to').val('').removeAttr('disabled').removeClass('hasDatepicker').datepicker({
        dateFormat: 'dd.mm.yy',
        minDate: date_diff,
        maxDate: maxDate_d
    });
});

$('#to').keyup(function () {
    $(this).val('');
    alert('Please select date from Calendar');
});
$('#from').keyup(function () {
    $('#from,#to').val('');
    $('#to').attr('disabled', 'disabled');
    alert('Please select date from Calendar');
});
});
  • 写回答

3条回答 默认 最新

  • dongliao6491 2016-12-29 04:54
    关注

    You can set your minDate variable to '3'. so it will start from two days after from your current date:

    Check this :

    set minDate: 3

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA