我试过了几个网站的一些HTML DOM代码,但它不工作。它没有添加任何东西。有没有人有这个工作的例子?用javascript将图像添加到html
this.img = document.createElement("img");
this.img.src = "img/eqp/"+this.apparel+"/"+this.facing+"_idle.png";
src = getElementById("gamediv");
src.appendChild(this.img)
但它没有添加任何东西到div。 (gamediv)我也试过document.body,没有结果。
在此先感谢。
this.img =使用document.createElement( “IMG”); this.img.src =“img/eqp /”+ this.apparel +“/”+ this.facing +“_ idle.png”; src = document.getElementById(“gamediv”); src.appendChild(this.img); 现在改变了它,但它仍然不会在div gamediv中弹出。 – Anonymous 2010-04-29 08:51:01
@klausbyskov:感谢您修复错字。 – 2010-04-29 08:53:14
@Anonymous:难道是'src'路径不正确?你可以尝试一个绝对路径的图像,你知道肯定存在吗?如:'http:// www.google.com/intl/en_com/images/logo_plain.png' – 2010-04-29 08:54:44