请问如何用JavaScript复制页面元素
比如<div>
     <input/>
     <table/>
     ...........
   </div>
点击按钮,然后在下面生成同样的div和里面的元素

解决方案 »

  1.   

    来个最简单的...
    <html> 
        <head> 
            <script type="text/javascript"> 
    window.onload=function(){
    divTemp=document.getElementsByTagName("div")[0].parentElement.innerHTML;
    }
    function a(){
    var a=document.getElementsByTagName("div")[0];
    a.parentElement.innerHTML+=divTemp;
    }
            </script> 
        </head> 
        <body> 
            <p>Use your mouse to click and double click the red square. </p> 
            <div style="width: 100px; height: 100px; background-color: red" 
                onmouseover="handleEvent(event)" 
                onmouseout="handleEvent(event)" 
                onmousedown="handleEvent(event)" 
                onmouseup="handleEvent(event)" 
                onclick="handleEvent(event)" 
                ondblclick="handleEvent(event)" id="div1"> </div> 
            <p> <textarea id="txt1" rows="15" cols="50"> </textarea> </p>
    <input type="button" value="11" onclick="a()"/> 
        </body> 
    </html>