2
我有这个代码,我只想出现在某个日期。哪些代码在Firefox,Chrome甚至是Safari浏览器中都能正常工作。但是代码不适用于IE。我不知道为什么。IE没有正确比较日期字符串
我发现IE中的.toLocaleString()用空格而不是逗号分隔它们。
function givingTuesdayCode(){
var isIE = /*@[email protected]*/false || !!document.documentMode;
var now = calcTime(-6);
var splitnow = "";
if (isIE){ splitnow = now.split(" "); }
else{ splitnow = now.split(","); }
if (splitnow[0] == "12/2/2014"){
$('.introrotation').html("<img style='width:100%; height:auto' class='givingTuesday' src='/graphics/PoliticGov_620x265.jpg' alt='Give to us'/> <a href='http://IllinoisState.edu/GivingTuesday' class='GiveButtonLink'>Giving Tuesday: Join us!</a> <p style='color:black; position:relative; top:-85px; margin:10px'>Black Friday and Cyber Monday have come and gone. Today, join your fellow Redbirds and make a gift that matters. Give today at <a href='http://IllinoisState.edu/GivingTuesday' class='GiveLink'>IllinoisState.edu/GivingTuesday</a></p>");
$('.introrotation').css({'height': '265px'
});
$('.toggleButton').css({'display': 'none'
});
}
function calcTime(offset){
var date = new Date();
var utc = date.getTime()+(360*60000);
var nd = new Date(utc+(3600000*offset));
return nd.toLocaleString();
}
您获得的价值和预期的价值是什么? – ArinCool 2014-12-04 17:58:12
为什么不直接使用'.toLocaleDateString'方法呢?另外,如果您打算使用* locale字符串*,您应该提及您想使用的语言环境。 “2014年12月2日”是你用'en-US'得到的,但'en-GB'将返回“02/12/2014”。避免将日期作为字符串进行比较可能更为明智。 – Sampson 2014-12-04 19:20:29