0

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'>"));
4

4 回答 4

0

一位发布者回答了他的答案,但他的答案是正确的!谢谢!!

cell.innerHTML = "<img src='menubar/ico_delete16.gif' width='16' height='16'>";
于 2012-08-16T10:39:47.950 回答
0

尝试用“innerHTML”替换“createTextNode”。

于 2012-08-16T10:27:12.153 回答
0

优雅的方式:

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'>";
于 2012-08-16T10:31:57.770 回答
0

这只是另一种方式。

var element1 = document.createElement("img");
element1.src= "menubar/ico_delete16.gif";
element1.width = 16;
element1.height = 16;
cell.appendChild(element1);
于 2012-08-16T10:33:13.610 回答