我试图将受感染的变量字符串添加为 html 类,但我得到了一组额外的“”。
setInterval(function(){
return function(){
fetch('http://127.0.0.1:5000/showTable')
.then(response => response.text())
.then(data => {
document.getElementById("table").innerHTML = data;
document.getElementById("table").className = data;
});
};
}(), 1000);
这在检查器中给了我这个类:
<p id="table" class=" "Green0" " >"Green0"</p>
如何删除多余的“”?
最佳答案
我认为 API 返回的是 JSON,而不是纯文本。您需要解析它。
setInterval(function(){
return function(){
fetch('http://127.0.0.1:5000/showTable')
.then(response => response.json())
.then(data => {
document.getElementById("table").innerHTML = data;
document.getElementById("table").className = data;
});
};
}(), 1000);
关于javascript - 如何从 html 类中删除额外的 ""组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61049486/