JQuery UI Datepicker,反转下拉列表中的一年的顺序 [英] JQuery UI Datepicker, reverse the order of the year in the dropdowns
问题描述
我不会建议您修改原始的ui。 datepicker.js作为 Cuong 建议,因为一旦您或另一个开发人员替换文件,您的更改将会丢失新版本发布。记住为了重新申请而进行了什么样的定制是不现实的。相反,您可以在自己的单独的JS中覆盖现有的 _generateMonthYearHeader
方法:
//存储原始,所以我们可以在我们的覆盖方法中调用它
$ .datepicker._generateMonthYearHeader_original = $ .datepicker._generateMonthYearHeader;
$ .datepicker._generateMonthYearHeader = function(inst,dm,dy,mnd,mxd,s,mn,mns){
var header = $($。datepicker._generateMonthYearHeader_original(inst, dm,dy,mnd,mxd,s,mn,mns)),
years = header.find('。ui-datepicker-year');
//反转年份
years.html(Array.prototype.reverse.apply(years.children()));
//返回我们的新html
return $('< div />')。append(header).html();
}
我刚写了这个工作,很好:)
I have a datepicker with changeyear: true. The 'year' drop down displays the title as 2009, then instead of the next year below the title being 2008, 2007, 2006 and so on it starts at 1999 and counts upwards. I can't seem to find an easy solution to reverse this order?
I wouldn't recommend editing the original ui.datepicker.js as Cuong suggested because your changes will be lost as soon as you or another developer replaces the file when a new version is released. Remembering what customisations have been made in order to re-apply is not practical. Instead, you can override the existing _generateMonthYearHeader
method in your own separate JS like so:
// store original so we can call it inside our overriding method
$.datepicker._generateMonthYearHeader_original = $.datepicker._generateMonthYearHeader;
$.datepicker._generateMonthYearHeader = function(inst, dm, dy, mnd, mxd, s, mn, mns) {
var header = $($.datepicker._generateMonthYearHeader_original(inst, dm, dy, mnd, mxd, s, mn, mns)),
years = header.find('.ui-datepicker-year');
// reverse the years
years.html(Array.prototype.reverse.apply(years.children()));
// return our new html
return $('<div />').append(header).html();
}
I just wrote this for something I'm working on and it does the trick nicely :)
这篇关于JQuery UI Datepicker,反转下拉列表中的一年的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!