这样看看,src换成图片的路径.
<html>
<head>
<script type="text/javascript">
function init(){
m_img = document.createElement("img");
m_img.setAttribute("src", "1.gif");
}
function show(){
div = document.getElementById("showDiv");
div.appendChild(m_img);
}
window.onload=function(){
init();
}
</script>
</head>
<body>
<div id="showDiv"></div>
<input type="button" onclick="show()" value="显示">
</body>
</html>
<html>
<head>
<script type="text/javascript">
function init(){
m_img = document.createElement("img");
m_img.setAttribute("src", "1.gif");
}
function show(){
div = document.getElementById("showDiv");
div.appendChild(m_img);
}
window.onload=function(){
init();
}
</script>
</head>
<body>
<div id="showDiv"></div>
<input type="button" onclick="show()" value="显示">
</body>
</html>
解决方案 »
- 这个 javaScript 怎么写
- 鼠标经过改变表格背景属性~~
- javascript一个方法,知道发告诉我一下
- 动态添加的embed SVG元素如何获得其svgdoc?
- 一个超级郁闷的问题...拖动实现了, 在IE下其子标签的事件却被屏蔽了
- 如何用js删除所有cookie,就象session.abandon一样
- 如何在鼠标事件中,改变TD里文字的大小呢?
- 天气预报怎么做?
- 请问哪里有HTMLREF.CHM中文版下载,最好版本要新一点的
- JSP获取的json数据中{}[]等变成了乱码
- 怎么才能让function返回(return)获取到的responseText?
- 请问各位老大关于引用外部 .js文件的问题,先谢谢了
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页</title>
<style type="text/css">
body{}
</style>
</head>
<body onload="init();">
<script>
function init(){
m_img = document.createElement("img"); //语句1
m_img.setAttribute("src", "http://d1.sina.com.cn/200709/20/107310_lunbobutton.gif"); //语句2
}然后,当用户点击某按钮时,立即显示该gif图片:
function show(){
div = document.getElementById("showDiv"); //语句3
div.appendChild(m_img); //语句4
}
</script>
<button onclick="show();">button</button>
<div id="showDiv"></div>
</body>
</html>
点击的时候create一个img节点 在append进去,这个节点的src和m_img一样就可以了
这样就会从cach中去取那张图片了,实现了预加载 图片也会动。