2 回答

TA貢獻1946條經(jīng)驗 獲得超4個贊
您最好將變量名稱從狀態(tài)
更改為其他名稱,因為 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條經(jīng)驗 獲得超3個贊
我想如果你在循環(huán)中聲明所有變量(var row = document...)(或者,如果你的味道允許的話,可以讓/康斯特)
我確實調(diào)試了代碼,并且我被迫聲明所有變量,并且它似乎工作正常(您提到的行上沒有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>
添加回答
舉報