这样看看,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>

解决方案 »

  1.   

    GIF在动啊。
    <!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>
      

  2.   

    你用一个隐藏层来放这个gif,即init中就把m_img append进隐藏层,
    点击的时候create一个img节点 在append进去,这个节点的src和m_img一样就可以了
    这样就会从cach中去取那张图片了,实现了预加载 图片也会动。