我要在top中添加img,可以
var div1=document.getElementById("top");
var img=document.createElement("image");
img.src="./Images/luobinmao.jpg";
div1.appendChild(img);
问题是此处动态添加的img在html中是没有标记的,此时怎么删除?
用removeChild不行!
var div1=document.getElementById("top");
var img=document.createElement("image");
img.src="./Images/luobinmao.jpg";
div1.appendChild(img);
问题是此处动态添加的img在html中是没有标记的,此时怎么删除?
用removeChild不行!
顶下!
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript">
window.onload=function(){
var div1=document.getElementById("div1");
var img=document.createElement("image");
img.setAttribute("id","image1");//设置id为image1
img.src="../1.jpg";
div1.appendChild(img);
}
function remove(){
var div1=document.getElementById("div1");
var img=document.getElementById("image1");
div1.removeChild(img);//通过id找到image并删除 }
</script>
</head>
<body>
<div id="div1">
<input id="Button1" type="button" value="button" onclick="remove()" />
</div>
</body>
</html>
怎么用?
div1.innerHTML = "";
ORimg.style.display = "none";