I are use timepicker jquery.我必须文本字段一个是"从",第二个是"到"。所以当时间从选择自动更新时间到字段时所以
$('#onselectExample').timepicker();
$('#onselectExample').on('changeTime', function() {
$('#onselectTarget').text($(this).val());
});
你想在
#onselectExample
发生变化时更改#onselectTarget
吗?它可以实现如下:
$('#onselectExample').timepicker({
onSelect: function(selectedDateTime){
$('#onselectTarget').text(selectedDateTime);
}
});
如果你想在选定的时间上增加30分钟,你可以写一个额外的基金:
$(function(){
$('#onselectExample').timepicker({
onSelect: function(selectedDateTime){
console.log(selectedDateTime);
$('#onselectTarget').text(add30Min(selectedDateTime));
}
});
});
function add30Min(oldTime){
var time = oldTime.split(":"); //split hours an minutes
var hours = time[0]; // get hours
var minutes = time[1]; // get minutes
if (+minutes >= 30){ // when minutes over 30
hours = (+hours+1)%24; // add an hour and convert 24 to 0
}
minutes = (+minutes + 30)%60; // add 30 minutes and convert 61 to 1
return $.datepicker.formatTime('hh:mm',{ // use formatTime to return formatted Time
'hour':hours,
'minute':minutes
});
}