По принцип трябва да промените тази част от http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerIntoSelects.html
Променете тази част, инициализацията на datePicker,
$(function()
{
// initialise the "Select date" link
$('#date-pick')
.datePicker(
// associate the link with a date picker
{
createButton:false,
startDate:'01/01/2005',
endDate:'31/12/2010'
}
към това, като добавите масива от месеци и актуализирате крайната дата.
$(function()
{
var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
// initialise the "Select date" link
$('#date-pick')
.datePicker(
// associate the link with a date picker
{
createButton:false,
startDate:'01/01/2005',
endDate:'31/12/2015'
}
След това променете функцията, която актуализира 3-те избрани (d,m,y)
var updateSelects = function (selectedDate)
{
var selectedDate = new Date(selectedDate);
$('#d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
$('#m option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
$('#y option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
}
до само (d,m) с месеца, посочен в този формат "август 2011".
var updateSelects = function (selectedDate)
{
var selectedDate = new Date(selectedDate);
$('#d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
$('#m option[value=' + (months[selectedDate.getMonth()]) + ' ' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
}
След това променете функцията, която актуализира инструмента за избор при промяна на избраните от това
// listen for when the selects are changed and update the picker
$('#d, #m, #y')
.bind(
'change',
function()
{
var d = new Date(
$('#y').val(),
$('#m').val()-1,
$('#d').val()
);
$('#date-pick').dpSetSelected(d.asString());
}
);
В това, (РЕДАКТИРАНЕ: погрешно размених стойността на годината и стойността на деня в предишния си отговор.)
// listen for when the selects are changed and update the picker
$('#d, #m')
.bind(
'change',
function()
{
var d = new Date(
$('#m').val().split(" ")[1],
months.indexOf($('#m').val().split(" ")[0]),
$('#d').val()
);
$('#date-pick').dpSetSelected(d.asString());
}
);
Това е http://jsfiddle.net/2Nedr/1/, който прави точно това. Надявам се това да реши проблема ви.
person
ace
schedule
02.08.2011