2 回答
TA贡献1946条经验 获得超4个赞
您最好将变量名称从状态
更改为其他名称,因为 window.status
是保留的
例
status = document.createElement("div") console.log(typeof status);
--编辑
工作实例
function processResult(responses) {
for (i = 0; i < responses.length ; i++) {
row = document.createElement("tr")
naam = document.createElement("td")
ema = document.createElement("td")
tit = document.createElement("td")
content = document.createElement("td")
status1 = document.createElement("td")
content.classList.add("text-justify")
var containeris = [naam, tit, content, status1];
naam.innerHTML = responses[i][1].split(" ")[0]
tit.innerHTML = responses[i][6]
status1.innerHTML = responses[i][11]
str = "<a href = 'javascript:trigger(" + i + ")'>[Read More]</a>"
content.innerHTML = responses[i][7].slice(0, 50) + "..." + str
containeris.forEach(function(el) {
row.appendChild(el);
});
document.getElementById("mytable").appendChild(row)
}
}
processResult([
Array(12).fill('Test')
])
#mytable {
border: 1px solid black;
padding: 1rem;
}
<table id="mytable"></table>
TA贡献1836条经验 获得超3个赞
我想如果你在循环中声明所有变量(var row = document...)(或者,如果你的味道允许的话,可以让/康斯特)
我确实调试了代码,并且我被迫声明所有变量,并且它似乎工作正常(您提到的行上没有js错误)
processResult([
[
'abc',
'def',
'ghi',
'jkl',
'mno',
'pqr',
'stu',
'vwx',
'yz1',
'234',
'567',
'890',
],
]);
function processResult(responses) {
debugger;
for (var i = 0; i < responses.length; i++) {
var row = document.createElement('tr');
var naam = document.createElement('td');
//var ema = document.createElement('td');
var tit = document.createElement('td');
var content = document.createElement('td');
var status = document.createElement('td');
content.classList.add('text-justify');
var containeris = [naam, tit, content, status];
naam.innerHTML = responses[i][1].split(' ')[0];
tit.innerHTML = responses[i][6];
var tc = document.createElement('span');
tc.textContent = responses[i][11];
status.appendChild(tc);
var str = "<a href = 'javascript:trigger(" + i + ")'>[Read More]</a>";
content.innerHTML = responses[i][7].slice(0, 50) + '...' + str;
containeris.forEach(function(el) {
row.appendChild(el);
});
document.getElementById('mytable').appendChild(row);
}
}
<table id="mytable"></table>
添加回答
举报