【发布时间】:2010-10-29 14:14:58
【问题描述】:
我想在 jQuery 中将日期字符串转换为日期对象,下面的代码适用于 Chrome 和 Firefox,但不适用于 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 中也能正常工作?
【问题讨论】: