Can someone please tell me how to display an image instead of this showing as text. I am using this part of a html table script. Thanks!
cell.appendChild(document.createTextNode("<img src='menubar/ico_delete16.gif' width='16' height='16'>"));
Can someone please tell me how to display an image instead of this showing as text. I am using this part of a html table script. Thanks!
cell.appendChild(document.createTextNode("<img src='menubar/ico_delete16.gif' width='16' height='16'>"));
一位发布者回答了他的答案,但他的答案是正确的!谢谢!!
cell.innerHTML = "<img src='menubar/ico_delete16.gif' width='16' height='16'>";
尝试用“innerHTML”替换“createTextNode”。
优雅的方式:
var imgEl = document.createElement("img");
imgEl.setAttribute("src", "menubar/ico_delete16.gif");
imgEl.setAttribute("width", 16);
imgEl.setAttribute("height", 16);
cell.appendChild(imgEl);
和原始的方式:
cell.innerHTML += "<img src='menubar/ico_delete16.gif' width='16' height='16'>";
这只是另一种方式。
var element1 = document.createElement("img");
element1.src= "menubar/ico_delete16.gif";
element1.width = 16;
element1.height = 16;
cell.appendChild(element1);