开始时间确定后,选择结束时间需要在开始时间之前。customData的默认值暂时没有修改,修改的有bug
customData修改:
var hour = date.getHours();
var Minute = date.getMinutes();
var completeHours = new Array([
{"text":"10:00","value":"10:00"}, {"text":"10:30","value":"10:30"},
{"text":"11:00","value":"11:00"}, {"text":"11:30","value":"11:30"},
{"text":"12:00","value":"12:00"}, {"text":"12:30","value":"12:30"},
{"text":"13:00","value":"13:00"}, {"text":"13:30","value":"13:30"},
{"text":"14:00","value":"14:00"}, {"text":"14:30","value":"14:30"},
{"text":"15:00","value":"15:00"}, {"text":"15:30","value":"15:30"},
{"text":"16:00","value":"16:00"}, {"text":"16:30","value":"16:30"},
{"text":"17:00","value":"17:00"}]);
if(Minute==0){
var completeHoursArr = completeHours[0].slice(2*(hour-10),15);
}else{var completeHoursArr = completeHours[0].slice(2*(hour-10)+1,15);}
options.customData = {"h":completeHoursArr};
以上有BUG.
html:
<div class="mui-input-group" style="">
<div class="mui-input-row">
<label>用车时间</label>
<input type="text" id="orderDateFrom" class="input-rent-datetime mui-text-right" readonly="readonly" placeholder="请选择" data- options='{"type":"hour","beginYear":2017,"customData":{"h":[
{"text":"10:00","value":"10:00"}, {"text":"10:30","value":"10:30"},
{"text":"11:00","value":"11:00"}, {"text":"11:30","value":"11:30"},
{"text":"12:00","value":"12:00"}, {"text":"12:30","value":"12:30"},
{"text":"13:00","value":"13:00"}, {"text":"13:30","value":"13:30"},
{"text":"14:00","value":"14:00"}, {"text":"14:30","value":"14:30"},
{"text":"15:00","value":"15:00"}, {"text":"15:30","value":"15:30"},
{"text":"16:00","value":"16:00"}, {"text":"16:30","value":"16:30"},
{"text":"17:00","value":"17:00"}]},"labels":["年", "月", "日", "时段", "分"]}'>
</div>
<div class="mui-input-row">
<label>还车时间</label>
<input type="text" id="orderDateTo" class="input-rent-datetime mui-text-right" readonly="readonly" placeholder="请选择"
data-options='{"type":"hour","beginYear":2017,"customData":{"h":[
{"text":"10:00","value":"10:00"}, {"text":"10:30","value":"10:30"},
{"text":"11:00","value":"11:00"}, {"text":"11:30","value":"11:30"},
{"text":"12:00","value":"12:00"}, {"text":"12:30","value":"12:30"},
{"text":"13:00","value":"13:00"}, {"text":"13:30","value":"13:30"},
{"text":"14:00","value":"14:00"}, {"text":"14:30","value":"14:30"},
{"text":"15:00","value":"15:00"}, {"text":"15:30","value":"15:30"},
{"text":"16:00","value":"16:00"}, {"text":"16:30","value":"16:30"},
{"text":"17:00","value":"17:00"}]},"labels":["年", "月", "日", "时段", "分"]}'>
</div>
</div>
js:
$('.input-rent-datetime').each(function(i, obj) {
obj.addEventListener('tap', function() {
var optionsJson = this.getAttribute('data-options') || '{}';
var options = JSON.parse(optionsJson);
var picker = new $.DtPicker(options);
if(obj.getAttribute("id")=="orderDateTo"){
var date= new Date(beginTime);;
options.beginYear=date.getFullYear();
options.beginMonth=date.getMonth()+1;
options.beginDay=date.getDate();
options.beginCustomData=date.getHours();
}
picker.show(function(rs) {
obj.value = rs.text;
picker.dispose();
beginTime = rs.text;
});
}, false);
});
方法2
var date= new Date(beginTime);
Year = date.getFullYear();
Month = date.getMonth()+1;
Day = date.getDate();
if(Month<10){
Month = "0"+Month;
}if(Day<10){
Day = "0"+Day;
}
time=Year+"-"+Month+"-"+Day;
picker.setSelectedValue(time);