有人能告訴我爲什麼這個代碼凍結ie8?它應該生成輸入字段。在Firefox,Safari瀏覽器,鍍鉻它的工作原理,但在IN8當我按下生成按鈕,它凍結javascript freezeing ie8
var monthNames = [ "Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie", "Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie" ];
function buildMonthlyEntries() {
var startDate = new Date(document.getElementById('datastart').value);
var endDate = new Date(document.getElementById('dataend').value);
if (startDate == "Invalid Date" || endDate == "Invalid Date") { return null; }
var monthlyEntries = document.getElementById('monthlyEntries');
monthlyEntries.innerHTML = "";
// inclusiv dataend
endDate.setMonth(endDate.getMonth() + 1);
// start with startDate; loop until we reach endDate
for (var dt = startDate;
! (dt.getFullYear() == endDate.getFullYear() && dt.getMonth() == endDate.getMonth());
dt.setMonth(dt.getMonth() + 1)
) {
monthlyEntries.appendChild(document.createTextNode(
monthNames[dt.getMonth()] + " " + String(dt.getFullYear()).substring(2)
));
var textElement = document.createElement('input');
var textElement2 = document.createElement('input');
var textElement3 = document.createElement('input');
textElement.setAttribute('type', 'text');
//textElement.setAttribute('name', 'entry['+ monthNames[dt.getMonth()] + + String(dt.getFullYear()).substring(2) + ']');
textElement.setAttribute('name', 'entry[]');
textElement2.setAttribute('type', 'hidden');
textElement2.setAttribute('name', 'luna[]');
textElement2.setAttribute('value', '' + monthNames[dt.getMonth()] + '');
textElement3.setAttribute('type', 'hidden');
textElement3.setAttribute('name', 'an[]');
textElement3.setAttribute('value', '' + String(dt.getFullYear()) + '');
monthlyEntries.appendChild(textElement);
monthlyEntries.appendChild(textElement2);
monthlyEntries.appendChild(textElement3);
// adauga br
// monthlyEntries.appendChild(document.createElement("br"));
}
return null;
}
你有沒有嘗試在IE中調試它也看到它凍結在哪裏? – TGH 2012-03-27 04:50:42
我不知道它是否與'dt.setMonth(dt.getMonth()+ 1)'在瀏覽器中有不同的行爲。 – ChaosPandion 2012-03-27 04:55:35
我試過沒有+1,仍然凍結 – florin 2012-03-27 05:03:54