如何在javascript中判断文本框中的日期不能大于当前日期吗?我的怎么不行
function CheckDate()
{
//获得当前时间
var now = new Date();
strYear = now.getYear();
strMonth = now.getMonth();
strDay = now.getDay();
var datetime = strYear +"-"+strMonth+"-"+strDay
var BirDate = document.getElementById("ctl00$mainContent$txtBirDate");
if(Trim(BirDate.value)>datetime.toString())
{
BirDate.value="";
document.getElementById("ctl00$mainContent$txtBirDate").focus();
}
}
function CheckDate()
{
//获得当前时间
var now = new Date();
strYear = now.getYear();
strMonth = now.getMonth();
strDay = now.getDay();
var datetime = strYear +"-"+strMonth+"-"+strDay
var BirDate = document.getElementById("ctl00$mainContent$txtBirDate");
if(Trim(BirDate.value)>datetime.toString())
{
BirDate.value="";
document.getElementById("ctl00$mainContent$txtBirDate").focus();
}
}
2009-8-28
2009-08-28
是不一样的
其实最好转化成日期类型,用valueOf比较
可以控制。