<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script type="text/javascript">
function replaceImg(){
var divNode=document.getElementById("div1");
var newImg=document.createElement("img");
newImg.setAttribute("src","/DOM/img/timg (1).jpg");//设置src属性
newImg.setAttribute("width","100");//设置宽属性
newImg.setAttribute("height","80");//设置高属性
var docBody=document.getElementsByTagName("body");
docBody[0].replaceChild(newImg,divNode);
}
</script>
<body>
<div id="div1">div文本内容</div>
<input type="button" value="将div 替换城图片"onclick="replaceImg()" />
</body>
</html>
。。。。。。。。。