我有一個包含數字的選擇列表。這些數字從0到30.我想根據當前日期和用戶設置的日期之間的天數來隱藏數字。如何在除Firefox以外的其他所有瀏覽器中使此工作成功
因此,如果今天是2010年7月28日,並且他們設置了2010年7月29日,它應該只顯示「0」。
如果是2010年7月28日,他們成立2010年9月20日它應該顯示0到30
所以我有這個
var selectedDate = new Date($('#TextBox').val().replace(/\/(\d\d)$/, "/20$1"));
var currentDate = new Date();
var month = currentDate.getMonth() + 1
var day = currentDate.getDate()
var year = currentDate.getFullYear()
currentDate = new Date(month + "/" + day + "/" + year);
if (isNaN(selectedDate) == false)
{
$('#selectList').find('select').attr('disabled', '');
var diffDays = parseInt((selectedDate - currentDate)/(1000 * 60 * 60 * 24));
var Options = $('#selectList').find('option');
jQuery.each(Options, function (i, value)
{
var currentValue = $(this).val();
if (currentValue == -1)
{
// equal to continue;
return true;
}
else if (currentValue >= diffDays)
{
$(this).hide();
}
else
{
$(this).show();
}
});
}
此代碼發生在用戶那裏的文本框的變化會選擇一個日期。
這在FireFox中正常工作,但在任何其他瀏覽器中都不起作用。我不知道爲什麼。任何瀏覽器都不顯示錯誤。
你有沒有試過'currentDate = new date(year,month-1,day);'? – Pointy 2010-07-28 21:47:19
我不確定'isNaN()'在使用'new Date()'構造的日期上工作。它肯定應該使用'Date.parse()'構造的時間戳。在檢查了isNaN()後,你可以使用'new Date(timestamp)'創建日期。 – 2010-07-28 21:53:02