2017-02-09 169 views
0

我有2個字段,DateFrom和DateTo,以及一個jQuery日期選擇器。如果今天是2月9日,我希望DateFrom字段顯示爲2017年1月1日,而DateTo字段顯示爲2017年1月31日。我如何在這個特定的環境中實現這一目標?設置一個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); 
相關問題