所以我让我的代码在Chrome中运行得很好。在FF我得到前两个警报与日期,他们的格式正确和一切,但如果选择过去的日期,它不会抛出第三个警报。在IE中,我得到了所有三个警报,但即使我选择了未来的日期。正如我所提到的,Chrome可以正常工作,所以如果有人能够提供一些洞察力,让它能够在所有这些方面发挥作用。
function check()
{
var selecteddate = document.form1.selectmonth.value + "-" + document.form1.selectday.value + "-" + document.form1.selectyear.value;
var d = new Date();
var today = (d.getMonth()+1) + "-" + d.getDate() + "-" + d.getFullYear();
// I'd then make some alerts and it'd return the selected date and today with no problem
alert(selecteddate);
alert(today)
//Now for the if statement is where it just stops working. I think maybe I'm doing
//something wrong just solely in the if statement.
if(new Date(selecteddate) < new Date(today))
{
alert("Past dates are not valid");
return false;
}
}
</script>
答案 0 :(得分:0)
您的日期对FF无效,请使用"/"
代替"-"
和selecteddate
的{{1}}。
或者只是使用
today
而不是
if(selecteddate < today)