2017-02-09 14 views
0

У меня есть 2 поля, DateFrom и DateTo, а также выбор даты jquery. Если сегодня 9 февраля, я хочу, чтобы поле DateFrom показывало 01 января-2017 и поле DateTo для показа 31 января-2017 года. Как я могу достичь этого в этом конкретном контексте?Задайте выбор даты в jquery, чтобы выбрать определенный диапазон дат

enter image description here

$(document).ready(function() { 
    $("#ddlDocument").change(function() { 
     $.ajax({ 
      type: "POST", 
      url: serviceName + "/GetMIRReportValueAdmin", 
      data: "{'Value':'" + $(this).val() + "'}", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      processdata: true, 
      success: function (msg) { 
       var data = msg.d; 
       $('#infocontent-body').hide(); 
       $('#divParams').html(data); 
       $('.date').datepicker({ constrainInput: true, duration: 'fast', gotoCurrent: true, dateFormat: 'd-M-yy', autoSize: true, showOn: 'focus', 
         changeMonth: true, changeYear: true, buttonImageOnly: true, buttonImage: baseUrl + 'Styles/Images/datepicker.gif', 
         minDate: new Date(curryear, 1, 1), maxDate: '+15y', yearRange: '1990:2030', 
         beforeShow: function (input, inst) { $(this).blur(); } 
        }); 
       ProductList(); //If there is a product list 
       StatusList(); //If there is a status list 

       if ($("#ddlDocument").find('option').filter(':selected').attr("aosSubparameter") == "Early Withdrawal Report") { 
        GetLifeCompanyList(); //If there is a fund list 
        $("#ddllifecompany").removeAttr('disabled'); 
       } 
       else FinancialProductList(); //If there is a financial product list 
       //FundList(); //If there is a fund list 
       CompanyList(); //If there is a company List example RA and nonRA 
       if ($("#ddlDocument").find('option').filter(':selected').attr("aosSubparameter") == "Investment Statement" || $("#ddlDocument").find('option').filter(':selected').attr("aosSubparameter") == "Growth Report" 
        || $("#ddlDocument").find('option').filter(':selected').attr("aosSubparameter") == "Actuaries Report") { 
        ProductFundList(); //If there is a fund list 
        GetLifeCompanyList(); //If there is a fund list 
        $("#ddllifecompany").removeAttr('disabled'); 
       } 
      }, 
      error: function (msg) { 
       alert('Failed to load the requested data.'); 
      } 
     }); 
    }); 
}); 

ответ

0

Как о чем-то вроде этого?

var date = new Date(), y = date.getFullYear(), m = date.getMonth(); 
    var firstDay = new Date(y, m-1, 1); 
    var lastDay = new Date(y, m-1 + 1, 0); 
    $(".selector").datepicker("setDate", firstDay); 
    $(".selector").datepicker("setDate", lastDay);