我终于过滤并检索了我表中想要的行,并为其分配了一个值,该值会正确输出到控制台,但不会呈现在网页本身上。我已将行检索到变量行中,并为其分配了另一个变量var rows = [...$(".table td")].map(e => $(e).text().trim()).filter(e => e);console.log(rows);for (i = 0; i < rows.length; i++) { //I have assigned it in the line below rows[i].text = dateArr[i]; console.log(rows[i]);}
1 回答

红颜莎娜
TA贡献1842条经验 获得超12个赞
如您在console.log(rows);中所见 您只会得到一个包含所有TD值的新字符串数组,而不是每个TD上的指针都包含无用的复杂代码
const newVals = [111,222,333];
document.querySelectorAll('#myTable td').forEach( (elmTD, idx)=>{
elmTD.textContent=newVals[idx].toString()
})
td { border:1px solid grey }
<table id="myTable">
<tr>
<td> aaa </td>
<td> bbb </td>
<td> ccc </td>
</tr>
</table>
我只能说“忘记jQuery并使用javascript ES6”只是因为您已经使用了箭头功能
添加回答
举报
0/150
提交
取消