innerHTML を置き換えるにはどうすればよいですか? アプリケーション全体で createElement、setAttribute の innerHTML を置き換えることは不可能です。
1 に答える
0
document.getElementById("information").innerHTML = info[0].getAttribute("text");
1 行のコードが 10 行になる...あまり実用的ではありませんが、他に方法はありません。
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);
于 2014-06-09T18:02:11.407 に答える