我输入的日期类型如下。 在上面的示例中,我无法选择当前日期。请帮忙。 检查添加的代码段
function CheckD()
{
var current=new Date(document.getElementById('task_date').value);
var today=new Date();
if(current.getTime() <= today.getTime())
{
alert("You Can't Assign Task For Expired Date");
document.getElementById('task_date').value="";
}
else
{
return true;
}
}
<input type="date" id="task_date" name="task_date" class="form-control" onchange="return CheckD();">
答案 0 :(得分:0)
可能是因为您使用的git clone
每秒会改变一次,所以在这种情况下getTime
是合适的
getDate
function CheckD() {
var current = new Date(document.getElementById('task_date').value);
var today = new Date();
if (current.getDate() < today.getDate()) {
alert("You Can't Assign Task For Expired Date");
document.getElementById('task_date').value = "";
} else {
return true;
}
}
答案 1 :(得分:0)
使用getDate()代替使用getTime()
function CheckD()
{
var current=new Date(document.getElementById('task_date').value);
var today=new Date();
if(current.getDate() < today.getDate())
{
alert("You Can't Assign Task For Expired Date");
document.getElementById('task_date').value="";
}
else
{
return true;
}
}
<input type="date" id="task_date" name="task_date" class="form-control" onchange="return CheckD();">
答案 2 :(得分:0)
理想情况下,您应该使用Akhil&brk指出的getDate()
,
但是出于某些原因,如果必须使用getTime()
,请将函数更改为:
function CheckD()
{
var current=new Date(document.getElementById('task_date').value);
var today=new Date();
today.setHours(0,0,0,0);// <-- this will effectively change time component to 00:00:00
if(current.getTime() < today.getTime())
{
alert("You Can't Assign Task For Expired Date");
document.getElementById('task_date').value="";
}
else
{
return true;
}
}
<input type="date" id="task_date" name="task_date" class="form-control" onchange="return CheckD();">
答案 3 :(得分:0)
只需更改
if(current.getTime() <= today.getTime())
对此
if(current.getDate() < today.getDate() )