js中创建img元素追加src属性添加图片 运行HTML图片不能加载
addLoadEvent(prepparePlaceholder);functionprepparePlaceholder(){varplaceholder=docume...
addLoadEvent(prepparePlaceholder);function prepparePlaceholder(){ var placeholder = document.createElement("img"); placeholder.setAttribute("id","placeholder"); placeholder.setAttribute("alt","图片加载失败"); placeholder.setAttribute("src","/img/m.jpg"); var descrittion = document.createElement("p"); descrittion.setAttribute("id","descrittion"); var txt1 = document.createTextNode("小飞马"); descrittion.appendChild(txt1); document.getElementsByTagName("body")[0].appendChild(placeholder); document.getElementsByTagName("body")[0].appendChild(descrittion);}//能够满足一个文档完全加载结束后执行多个onloadfunction addLoadEvent(func){ var oldonload=window.onload; if(typeof window.onload!='function'){ window.onload=func; }else { window.onload=function(){ oldonload(); func(); } }}/////////////////////////////////////////////////////////////////////////////////// <h1>Snapshots</h1> <ul id="imagegallery"> <li> <a href="img/1.jpg" title="耳朵"><img src="img/1.jpg"/></a> </li> <li> <a href="img/2.jpg" title="肩膀"><img src="img/2.jpg"/></a> </li> <li> <a href="img/3.jpg" title="死亡射线"><img src="img/3.jpg"/></a> </li> <li> <a href="img/4.jpg" title="背"><img src="img/4.jpg"/></a> </li> </ul>
展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询