0

Hi I am currently a newbie and practicing jquery and javascript, I have a problem with the end date , I am using datepicker.

Here is the Source Code

http://jsfiddle.net/zz9u4/704/

This is the Jquery code

$(function(){
    $("#txtFromDate").datepicker({
        minDate:0,
        maxDate: "+60D",
        numberOfMonths: 2,
    });
    $("#txtToDate").datepicker({ 
        minDate:0,
        maxDate:"+60D",
        numberOfMonths: 2,
    }); 
    var default_date = new Date();
    default_date.setDate(default_date.getDate()+60);
    $('#txtFromDate').datepicker('setDate', new Date());
    $('#txtToDate').datepicker('setDate', default_date);
});
$("#txtFromDate").datepicker({
    onSelect: function(dateText) {
        $("#txtToDate").datepicker("option", "minDate", $('#txtFromDate').datepicker("getDate") );
        var date2 = $("#txtFromDate").datepicker("getDate");
        date2.setDate(date2.getDate()+60);
4

2 回答 2

0

尝试测试此代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<style>
body
{
    font-size:8pt;
    font-family:Verdana;
    padding: 5px;
}

.ui-datepicker-calendar a {
  color: white !important;
  background-color: black !important;
  border-color: black;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
</head>
<body>

<br/>
From: <input type="text" id="txtFromDate" />
To: <input type="text" id="txtToDate" />
<p id="dataDate"></p>
<script type="text/javascript">
$(function(){
    $("#txtFromDate").datepicker({
        minDate:0,
        //maxDate: "+60D",
        numberOfMonths: 2,
    });
    $("#txtToDate").datepicker({ 
        minDate:0,
        //maxDate: "+60D",
        numberOfMonths: 2,
    }); 
    var default_date = new Date();
    default_date.setDate(default_date.getDate()+60);
    $('#txtFromDate').datepicker('setDate', new Date());
    $('#txtToDate').datepicker('setDate', default_date);
});
$("#txtFromDate").datepicker({
    onSelect: function(dateText) {
        $("#txtToDate").datepicker("option", "minDate", $('#txtFromDate').datepicker("getDate") );
        var date2 = $("#txtFromDate").datepicker("getDate");
        var d = date2.getFullYear()+'/'+date2.getMonth()+'/'+date2.getDate()+60;
        $('#txtToDate').datepicker("setDate", date2.getDate()+60);
      $('#dataDate').text(new Date(date2.getFullYear(),date2.getMonth(),date2.getDate()+60)+ '00000'+date2+'ppp'+date2.getDate());
        //$("#txtToDate").datepicker("option", "maxDate", date2);
    }
});
</script>

</body>
</html>

我的提琴手是: https ://jsfiddle.net/8o3LmLxt/

你似乎做的错误的事情是在这一行:

var date2 = $("#txtFromDate").datepicker("getDate");
       date2.setDate(date2.getDate()+60);

您正在使用 fromdate 作为今天。设置日期:

$('#txtToDate').datepicker("setDate", date2.getDate()+60);

期待对你有帮助

(我从代码中的 datepicker 中删除了限制 +60D)

于 2016-12-09T06:57:33.807 回答
0

请替换txtToDate的波纹管代码

$("#txtToDate").datepicker({ 
    minDate:0,
    numberOfMonths: 2,
    maxDate: "+60D",
    onClose: function() {
        $("#aDateFrom").datepicker(
                "change",
                { minDate: new Date($('#txtFromDate').val()) }
        );
    }
}); 
于 2016-12-09T06:42:56.413 回答