【发布时间】:2011-09-08 09:46:15
【问题描述】:
我正在用 javascript/asp.net 构建日历。
当我打印出日历时,我想每天检查是否有要显示的项目(约会)。这是函数的一部分:
for (var i = 1; i <= monthdays[month - 1]; i++) {
curnum++;
td = tr.insertCell(-1);
td.style.height = "95px";
td.style.width = "131px";
html = "<div id=\"divday" + year + "" + month + "" + i + "\" style=\"position:relative; left:0px; top:0px; width130px; height:95px; background-color:" + colors[i % 2] + "; cursor:pointer; \" onclick=\"openDay(" + year + "," + (month < 10 ? "0" + month : month) + "," + (i < 10 ? "0" + i : i) + ")\">";
html += "<div class=\"blackl\" style=\"position:absolute; left:100px; top:0px; width:30px; height:20px; text-align:right; \">" + i + "</div>";
html += "</div>";
td.innerHTML = html;
if (curnum == 7) {
tr = tbl.insertRow(-1);
curnum = 0;
}
if(i == 1) RCalendar.GetCalendarEvents(agentid, year, month, i, function (result) { setCalendarEvents(year, month, i, result) });
最后一行不应该有 if (i == 1) 它只是为了调试。我想调用网络服务并为每一天 (i) 编写项目。
这里是回调函数:
function setCalendarEvents(y, m, d, result) {
var daydiv = document.getElementById("divday" + y + m + d);
for(var i = 0; i < result.length; i++) {
var thiscalendaritem = result[i];
daydiv.innerHTML += makeCalendarItem(thiscalendaritem);
}
}
如果我在调用 web 服务的地方和回调函数中设置断点,i 和 d 就不一样了。当它被调用时,i 是 1(很明显),但是在 setCalendarEvents 中,当它被调用时,d 是 31。
【问题讨论】:
标签: javascript asp.net web-services for-loop