I have an HTML code like this one:
我有一个像这样的HTML代码:
<form action="#" method="get">
<input type="date">
</form>
I want to have an event or something that will check when the date is changed, and get the date in JS Date object?
我想要一个事件或什么东西来检查日期何时更改,并在JS Date对象中获取日期?
3 个解决方案
#1
#2
2
Attach the change
event handler and convert the value into Date
:
附加更改事件处理程序并将值转换为Date:
$("input").on("change", function () {
var myDate = new Date($(this).val());
console.log(myDate, myDate.getTime());
});
#3
0
You need to use a .change() jquery handler it will look something like this:
你需要使用.change()jquery处理程序,它看起来像这样:
$(document).ready(function(){
$('#dateInput').change(function(){
console.log('Updated Date');
});
});
<form>
<input id="dateInput" type="date" />
</form>
#1
3
Try change
event handler on the input
,
尝试在输入上更改事件处理程序,
$(document).ready(function(){
$('input[type="date"]').change(function(){
alert(this.value); //Date in full format alert(new Date(this.value));
var inputDate = new Date(this.value);
});
});
#2
2
Attach the change
event handler and convert the value into Date
:
附加更改事件处理程序并将值转换为Date:
$("input").on("change", function () {
var myDate = new Date($(this).val());
console.log(myDate, myDate.getTime());
});
#3
0
You need to use a .change() jquery handler it will look something like this:
你需要使用.change()jquery处理程序,它看起来像这样:
$(document).ready(function(){
$('#dateInput').change(function(){
console.log('Updated Date');
});
});
<form>
<input id="dateInput" type="date" />
</form>