Home >Web Front-end >JS Tutorial >Solve the localization and Today problem of jquery's datepicker_jquery

Solve the localization and Today problem of jquery's datepicker_jquery

WBOY
WBOYOriginal
2016-05-16 17:53:171135browse

1. Localization
can load the file directly, or add the following statement directly after the script

Copy the code The code is as follows:

jQuery(function ($) {
$.datepicker.regional['zh-CN'] = {
closeText: 'Close',
prevText: 'nextText: 'Next month>',
currentText: 'Today',
monthNames: ['January', 'February', 'March', 'April', ' May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'],
monthNamesShort: ['one', 'two', 'three', 'four', 'five', 'six',
'seven', 'eight', 'nine', 'ten', 'eleven', ' Twelve'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sunday ', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesMin: ['Day', 'Monday', 'Two', 'Wednesday' ', '四', '五', '六'],
weekHeader: 'week',
dateFormat: 'yy-mm-dd',
firstDay: 1,
isRTL: false ,
showMonthAfterYear: true,
yearSuffix: 'year'
};
$.datepicker.setDefaults($.datepicker.regional['zh-CN']);
});

2. Click Today to display the date directly in the input, instead of jumping to today's place and requiring the user to click the date again. The modification method is very simple, add this code in the script
Copy code The code is as follows:

$.datepicker._gotoToday = function (id) {
var target = $(id);
var inst = this._getInst(target[0]);
if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
inst.selectedDay = inst.currentDay;
inst.drawMonth = inst.selectedMonth = inst.currentMonth;
inst.drawYear = inst.selectedYear = inst.currentYear;
}
else {
var date = new Date();
inst.selectedDay = date.getDate();
inst.drawMonth = inst.selectedMonth = date.getMonth();
inst.drawYear = inst.selectedYear = date .getFullYear();
this._setDateDatepicker(target, date);
this._selectDate(id, this._getDateDatepicker(target));
}
this._notifyChange(inst);
this._adjustDate(target);
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn