如何使用javascript在ul標籤中創建元素li img標籤?如何使用javascript在ul標籤中創建元素li img標籤?
我想創建
<li id="123">
<img src="https://upload.wikimedia.org/wikipedia/commons/5/53/Loading_bar.gif"/>
</li>
內
<ul id="placehere">
但是不行,我該怎麼做呢?
https://jsfiddle.net/btz69dyk/2/
<body>
<script type="text/javascript">
window.onload=function(){
var elem = document.createElement("li");
elem.setAttribute("id", "123");
var elem = document.createElement("img");
elem.setAttribute("src", "https://upload.wikimedia.org/wikipedia/commons/5/53/Loading_bar.gif");
elem.setAttribute("height", "");
elem.setAttribute("width", "");
elem.setAttribute("alt", "Flower");
document.getElementById("placehere").appendChild(elem);
}
</script>
<ul id="placehere">
</ul>
</body>