如何替换innerHTML?替换createElement上的innerHTML,整个应用程序中的setAttribute都不可能。
答案 0 :(得分:0)
document.getElementById("information").innerHTML = info[0].getAttribute("text");
一行代码变成了几十......不太实用,但别无其他。
var informationDiv1 = document.createElement('div');
var informationDiv2 = document.createElement('div');
var informationDiv3 = document.createElement('div');
var informationImg = document.createElement('img');
informationDiv1.setAttribute("class", "panel panel-primary");
informationDiv1.setAttribute("style", "margin: 20px;");
informationDiv2.setAttribute("class", "panel-body text-justify");
informationDiv2.textContent = info[0].getAttribute("text");
informationDiv3.setAttribute("class", "text-center");
informationImg.setAttribute("src", "/img/gif2.gif");
informationImg.setAttribute("style", "width: 235px; margin-bottom: 20px;");
informationImg.setAttribute("class", "img-thumbnail");
informationDiv1.appendChild(informationDiv2);
informationDiv3.appendChild(informationImg);
informationDiv1.appendChild(informationDiv3);
document.getElementById("information").appendChild(informationDiv1);