js中创建img元素追加src属性添加图片 运行HTML图片不能加载
时间:2018-01-17 15:54:34
addLoadEvent(prepparePlaceholder);function prepparePlaceholder(){var placeholder = document.createElement("img");placeholder.setAttribute("id","placeholder");placeholder.setAttribute("alt","图片加载失败");placeholder.setAttribute("src","imgm.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 oldοnlοad=window.onload; if(typeof window.onload!=function){ window.οnlοad=func; }else { window.οnlοad=function(){ oldonload(); func(); } }}h1Snapshotsh1ul id="imagegallery"lia href="img1.jpg" title="耳朵"img src="img1.jpg"alilia href="img2.jpg" title="肩膀"img src="img2.jpg"alilia href="img3.jpg" title="死亡射线"img src="img3.jpg"alilia href="img4.jpg" title="背"img src="img4.jpg"aliul