0
所以我讓我的代碼在Chrome中正常工作。在FF中,我獲得了前兩個警報的日期,並且它們的格式正確,但是如果選擇過去的日期,它不會拋出第三個警報。在IE中我可以得到所有的三個警報,但即使我選擇了未來的日期。正如我所說的,Chrome的工作原理應該如此,如果任何人都可以提供一些洞察力,讓它在整個工作過程中發揮出色,那就很好。JavaScript驗證的跨瀏覽器問題
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>
http://grover.open2space.com/jquery.dates/home什麼? – Jerome
您可能希望使用'new Date(year,month,day [,hour,minute,second,millisecond])'構造函數,而不是依賴日期的字符串表示形式的構造函數。 https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date – Prusse
@jeromeG這看起來像一個日曆控件?我不想爲此項目使用日曆控件。儘管感謝您的鏈接,我可能會在未來的項目中使用它。 –