我正在尝试从HTML输入中提取日期和时间值,但似乎无法提取这些值。当尝试在浏览器控制台中输出数据时,它只显示“输入”而不是值本身。这些将是一个类似于形式的示例,但用于休息调用。见下面的例子。如果您需要更多信息,请与我们联系。
HTML:
<div id="dates">
Start Date: <input type="date" id="start" name="start">
Start Time: <input type="time" id="timestamp1" name="timestamp1" step="1">
<br/>
End Date: <input type="date" id="end" name="end">
End Time: <input type="time" id="timestamp2" name="timestamp2" step="1">
</div>
落镖:
//capture dates
var startDate = (shroot.querySelector('#start') as DateInputElement);
var endDate = (shroot.querySelector('#end') as DateInputElement);
var warn = (shroot.querySelector('#warning').text="");
var timestamp1 = (shroot.querySelector("#timestamp1") as TimeInputElement);
var timestamp2 = (shroot.querySelector("#timestamp2") as TimeInputElement);
//button click to handle request
button.onClick.listen((e) {
print(startDate);
print(endDate);
print(timestamp1);
print(timestamp2);
});
答案 0 :(得分:1)
正如@melmac写的那样
button.onClick.listen((e) {
print(startDate.value);
print(startDate.valueAsDate);
print(startDate.valueAsNumber);
print(timestamp1.value);
print(timestamp1.valueAsDate);
print(timestamp1.valueAsNumber);
});
2014年7月17日
2014-07-17 02:00:00.000 // GMT !! 1405555200000.011点12分十三秒
1970-01-01 12:12:13.000 // GMT !! 40333000.0