我想一个日期字符串转换为jQuery的日期对象,下面的代码工作正常,Chrome和Firefox,但不是在Internet Explorer中:在jQuery和Internet Explorer中将字符串转换为日期?
<script type="text/javascript" charset="utf-8">
//Validate if the followup date is now or passed:
jQuery.noConflict();
var now = new Date();
jQuery(".FollowUpDate").each(function() {
if (jQuery(this).text().trim() != "") {
var followupDate = new Date(jQuery(this).text().trim()); //Here's the problem
alert(followupDate);
if (followupDate <= now) {
jQuery(this).removeClass('current');
jQuery(this).addClass('late');
}
else {
jQuery(this).removeClass('late');
jQuery(this).addClass('current');
}
}
});
</script>
警报是唯一没有进行测试,并在Chrome和Firefox它返回一个日期对象,但在IE中我得到了NaN。
怎么回事,我该如何做这个转换,以便它能在IE中工作?
这是一种到现在为止,我已经开始了:-)但无论如何,我会在某个时候尝试一下! – Anders 2011-02-16 07:20:46
这基本上工作。现在让我们说,我有两个增值税从这个返回的值....可以从彼此扣除? – WilfredMifsud 2012-01-25 14:20:54
如果它们由此函数返回,则它们可能无法相互扣除,因为该函数返回一个字符串。我建议在调用这个函数前在日期做任何数学运算。 – 2012-01-25 14:26:16