我想在提交表单时发送用户日期时间选择的纪元格式值
你能告诉我我是怎么做到的吗? http://s529471052.onlinehome.fr/datetimeform/gpio/test5.htm我希望用GET方法发送epoch数据,如下所示:/test5.htm?datetime = 1494335700
目前,它发送了一些在后端无法使用的优秀格式:
/test5.htm?datetime=29+December+2016 + - + 10%3A50&安培;提交=
-
顺便说一下,由于某些未知原因'删除'和'日历'即使css文件存在,也不会在datetimeform中显示graphicon图标。
答案 0 :(得分:1)
由于您使用的“DateTimePicker”库似乎没有任何支持,因此您必须自行修补。
首先为现有的#dtp_input1
元素添加name
,以便将其作为参数发送:
<input id="dtp_input1" name="dtp_input1" type="hidden"/>
接下来我们需要挂钩选择器的setValue()
方法,以便将字段的值放入我们想要的格式中:
/* get the datetimepicker controller */
let picker = $(`.form_datetime`).data(`datetimepicker`);
/* override its setValue() method */
let f = picker.setValue;
picker.setValue = function(...xs) {
/* call the original method first */
f.call(this, ...xs);
/* now set the linked field to epoch format */
$(`#${this.linkField}`)
.val(`${(this.getDate() || new Date(0)).getTime()}`);
};
现在,当您提交表单时,它应该产生如下所示的查询:
?datetime=20+January+2017+-+03%3A15&dtp_input1=1484842500000
其中dtp_input1
是纪元价值,datetime
是文字框中的人类可读字符串。