You're getting a false negative because comparing 2 date objects compares their references and not their values as you perhaps expected.
There are a few options, you could store the result of Date.getTime()
in your array which is just a numerical representation of the date:
var holidayArray2013 = [
new Date('October 3, 2013 00:00:00 GMT+0200').getTime(),
new Date('December 25, 2013 00:00:00 GMT+0100').getTime(),
new Date('December 26, 2013 00:00:00 GMT+0100').getTime()];
And then compare that:
var DateOfOrder = n$('#datepicker').datepicker('getDate').getTime();
if ($.inArray(DateOfOrder, holidayArray2013) > -1) ...
This works fine, as demonstrated here: http://jsfiddle.net/rRJer/
If, however you are constrained to not changing the holiday array you could loop to try to locate the right date value:
var isHoliday = false;
for(var i=0;i<holidayArray2013.length;i++){
if(holidayArray2013[i].getTime() == DateOfOrder.getTime()){
isHoliday = true;
break;
}
}
Demo is here: http://jsfiddle.net/3R6GD/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…