jQuery UI - Datepicker - Hide year

后端 未结 5 1052
庸人自扰
庸人自扰 2021-01-02 01:14

I\'m using jQuery UI 1.8 and I would like to hide the year from the user in both the popup and the textbox. Essentially instead of picking the day, month and year I want the

5条回答
  •  佛祖请我去吃肉
    2021-01-02 01:39

    I dont think this option is exposed va the api. I belive that the easiest way is to change the stylesheet. Change the ui-datepicker-year class to display: none Another option would be to edit the source so it isnt rendered at all, to do that you can remove this part of the code:

    // year selection
    if (secondary || !changeYear)
        html += '' + drawYear + '';
    else {
        // determine range of years to display
        var years = this._get(inst, 'yearRange').split(':');
        var thisYear = new Date().getFullYear();
        var determineYear = function(value) {
            var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :
        (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :
        parseInt(value, 10)));
        return (isNaN(year) ? thisYear : year);
        };
        var year = determineYear(years[0]);
        var endYear = Math.max(year, determineYear(years[1] || ''));
        year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
        endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
        html += '';
    }
    

    I haven't tried removing the code but it should work. I did try hiding it using css and that does work (in firefox anyway :) )

    HTH

提交回复
热议问题