簡體   English   中英

jQuery DatePicker YearRange基於當前月份

[英]Jquery DatePicker YearRange based on current month

我正在使用Jquery的Datepicker,我想知道是否有可能根據當前月份更改yearRange屬性。

就我而言,如果月份與11月或12月不同,則將其當年范圍

否則是當前年份+ 1

范例1:

本月:4月

.datepicker({
        showOn: "button",
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        yearRange: '-12:+0'

范例2:

本月:11月

.datepicker({
        showOn: "button",
        buttonImage: "../../App_Themes/Samae/images/calendar.png",
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        yearRange: '-12:+1'

謝謝!

jQuery代碼

$(function () {
    var d = new Date();
    var month = d.getMonth();
    var range;
    if (month == 10 || month == 11) {
        range = '-12:+1';
    } else {
        range = '-12:+0';
    }
    $('#txtDate').datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: range
    });
});  

您可以通過更改條件來檢查它的運行情況, if (month == 03 || month == 11)

備用

$(function () {
    var d = new Date();
    var month = d.getMonth();
    $('#txtDate').datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: (month == 10 || month == 11) ? '-12:+1' : '-12:+0'
    });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM