未被捕获的IndexSizeError:无法在'HTMLTableRowElement'上执行'insertCell':提供的值(1)超出范围[-1,0] [英] Uncaught IndexSizeError: Failed to execute 'insertCell' on 'HTMLTableRowElement': The value provided (1) is outside the range [-1, 0]
问题描述
为什么图片没有显示在我的页面上?未被捕获的IndexSizeError:无法在'HTMLTableRowElement'上执行'insertCell':提供的值(1)超出范围[-1,0]-此字符串的错误调用.
Why pictures don't appear on my page? Uncaught IndexSizeError: Failed to execute 'insertCell' on 'HTMLTableRowElement': The value provided (1) is outside the range [-1, 0] - this error call on this string.
[JS]var cell = row.insertCell(i);[/JS]
function createPreview() {
var f = document.createElement("table");
var row = f.insertRow();
var cell = row.insertCell(i);
for(var j = 0; j < count ; j++) {
var img = new Image();
img.src = "image/" + j + ".jpg";
img.id = "i" + j;
cell.appendChild(img);
}
document.body.appendChild(f);
}
</script>[/JS]
推荐答案
这很旧,但是对于到达此处并遇到相同问题的任何人,您必须将第一个要放入的单元格设为单元格0,然后,您可以将单元格1,例如:您不能将单元格0放在其后,然后将其放在单元格2中,因为您需要一个单元格1.
This is old, but for anyone reaching here, and having the same problem, the first cell you have to put in a row is the cell 0, then, you can put the cell 1, for example: You cant put the cell 0, and after that the cell 2, because you need a cell 1.
方法是插入单元格0、1、2、3 ...
The way to do it is insert cell 0,1,2,3...
这篇关于未被捕获的IndexSizeError:无法在'HTMLTableRowElement'上执行'insertCell':提供的值(1)超出范围[-1,0]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!