我想一個日期字符串轉換爲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