我正试图从我的datepicker获取纪元日期。我尝试通过HTML在datepicker上放置一个带altFormat的altField,但是当尝试使用JavaScript获取值时,它为null:
HTML -
<input onchange='Refresh()' name="logging_from" id="logging_from" type="date" data-role="datebox" data-options='{"mode": "calbox","overrideDateFormat":"%d-%b-%y", "showInitialValue":true, "altField": "#epochdate","altFormat": "@" }'>
JavaScript -
var loggingfromactual = document.getElementById("epochdate").value;
任何帮助将不胜感激,谢谢!
答案 0 :(得分:0)
以下是几个选项:
处理输入的更改事件,获取日期并转换为纪元(date.getTime()/ 1000)
<input name="logging_from" id="logging_from" type="text" data-role="datebox"
data-options='{
"useNewStyle":true,
"mode": "calbox",
"overrideDateFormat":"%d-%b-%y"
}' />
$("#logging_from").on("change", function(){
alert("Epoch of sel date is " + dateToEpoch($(this).datebox('getTheDate')));
});
function dateToEpoch(thedate){
return thedate.getTime() / 1000;
}
<强> DEMO 强>
或,在日历上添加一个关闭回调:
<input name="logging_from" id="logging_from" type="text" data-role="datebox"
data-options='{
"useNewStyle":true,
"mode": "calbox",
"overrideDateFormat":"%d-%b-%y" ,
"closeCallback":"onCloseCalendar",
"closeCallbackArgs":["out_date"]
}' />
function onCloseCalendar(thedate){
alert("Epoch for sel date is " + dateToEpoch(thedate));
}
function dateToEpoch(thedate){
return thedate.getTime() / 1000;
}
<强> DEMO 强>