有没有一个方法能够实现追加一个div,并且包容网页body内的所有代码?

解决方案 »

  1.   

    <html>
    <script>
    window.onload=function(){
        var div=document.createElement("div");
        div.innerHTML=document.body.innerHTML;
        document.body.innerHTML="";
        document.body.appendChild(div);
    };
    </script>
    <body>ssss
    </body>
    </html>
      

  2.   

    这个应该你是要的<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>无标题文档</title>
    <style type="text/css">
    #topDiv{ position:absolute; z-index:3; width:100%;height:100%;background:#000; display:none;top:0;left:0;}
    #topDiv div{position:absolute; z-index:2;width:500px;height:500px; margin:-250px;left:50%;top:50%;padding:0;background:#fff;}
    #topDiv div textarea{width:100%;height:100%;}
    </style>
    <script src="../js/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function() {
            $('#show').click(function() {
                $('body').after('<div id="topDiv"></div>');
                $('#topDiv').fadeTo('slow', 0.5, function() {
                $(this).html('<div><textarea>' + $('body').html() + '</textarea></div>');
                });
            });
        })
    </script>
    </head>
    <body>
    <a id="show">Top Div</a>
    <p>
    abcdefg
    </p>
    <dl>
    <dt>abcdefg</dt>
    <dd>abcdefg</dd>
    <dd>abcdefg</dd>
    <dl>
    <h1>1111</h1>
    <h2>2222</h2>
    </body>
    </html>
      

  3.   

    var d=document.createElement("div"),
    childs=document.body.childNodes,
    len=childs.length,i=0;
    for(;i<len;i++){
        d.appendChild(childs[i]);
    }
    document.body.appendChild(d);
      

  4.   

    其实我要做的效果是新增一个最大容器的DIV,然后通过滤镜把网页内当前的内容旋转90°1L的方法我最早也这么想的,只是认为开销太大