Internet Explorer 中的 html dom 动态表
您好,我目前正在练习 HTML DOM,并且我已经编写了这个函数来创建动态表。
function initScheduleTable() {
var days = new Array("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN");
var table = document.getElementById("schedule");
var hourPerDay = 24;
var row, cell;
var i, j;
// Time headers
row = table.insertRow(-1);
cell = row.insertCell(-1);
for(i = 0; i < hourPerDay; ++i) {
cell = row.insertCell(-1);
if(i < 10)
cell.innerHTML = "0" + i;
else
cell.innerHTML = i;
}
for(i = 0; i < days.length; ++i) {
row = table.insertRow(-1);
cell = document.createElement("th");
cell.innerHTML = days[i];
row.appendChild(cell);
for(j = 0; j < hourPerDay; ++j) {
cell = row.insertCell(-1);
cell.innerHTML = " ";
}
}
}
这适用于 Chrome 和 Firefox,但不适用于 IE9。使用 IE,日期显示在最右边的列中。我使用 IE 开发人员工具检查了源代码,它显示 列在
列表的末尾。
这种情况下IE有什么需要注意的吗?
Hi i'm currently practicing HTML DOM and i've written this function to create a dynamic table.
function initScheduleTable() {
var days = new Array("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN");
var table = document.getElementById("schedule");
var hourPerDay = 24;
var row, cell;
var i, j;
// Time headers
row = table.insertRow(-1);
cell = row.insertCell(-1);
for(i = 0; i < hourPerDay; ++i) {
cell = row.insertCell(-1);
if(i < 10)
cell.innerHTML = "0" + i;
else
cell.innerHTML = i;
}
for(i = 0; i < days.length; ++i) {
row = table.insertRow(-1);
cell = document.createElement("th");
cell.innerHTML = days[i];
row.appendChild(cell);
for(j = 0; j < hourPerDay; ++j) {
cell = row.insertCell(-1);
cell.innerHTML = " ";
}
}
}
This works fine for Chrome and Firefox but not IE9. With IE the days are displayed on the rightmost column. I checked the source using IE developer's tool and it shows that <th>
is listed at the end of a list of <td>
.
Is there anything to be paid attention for IE in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于某种荒谬的原因,IE 认为 TH 单元格一定位于行的末尾。将每行上的 TH 更改为 TD,并使用 CSS 使其文本变为粗体,使其看起来像 TH。
For some absurd reason, IE thinks that TH cells must be at the end of a row. Change the TH on each row to a TD and use CSS make its text bold so it looks like a TH.