我试图用javascript比较两个日期。实际上,我的目标得到警告信息,如果第一次约会大于第二次约会,但javascript不能正常工作。当我调试火狐游标去else块,即使发生条件。同时,类似的javascript代码可以在jsfiddle上正常工作。
http://jsfiddle.net/Mjora/ZNaMW/Javascript代码
$("#btn").click(function(){
var firstDate = $('#firstDate').val();
var lastDate = $('#lastDate').val();
if (firstDate > lastDate) {
alert("First date can not be greater than Last date!!");
}
else{...}
});
我也试过这样的代码;
$("#btn").click(function(){
var firstDate = $('#firstDate').val();
var lastDate = $('#lastDate').val();
if (new Date(firstDate) > new Date(lastDate)) {
alert("First date can not be greater than Last date!!");
}
else{...}
});
/********/
var fDate="10.10.2020";
var lDate="10.10.2010";
var fDateSpl= fDate.Split(".");
var lDateSpl= lDate.Split(".");
var newFDate = new Date(fDateSpl[2], fDateSpl[1], fDateSpl[0]);
var newLDate = new Date(lDateSpl[2], lDateSpl[1], lDateSpl[0]);
if (newFDate > newLDate) {
alert("First date can not be greater than Last date!!");
}
else{...}