本帖最后由 mingfish 于 2009-09-29 11:30:34 编辑

解决方案 »

  1.   

    <script type="text/javascript" src="jquery-1.3.1.js"></script>
    <script>
    jQuery.fn.extend( {
      outerHTML: function( replacement )
      {
        if (replacement)
        {
          return this.each(function (){ $(this).replaceWith(replacement); });
        }
        var index = $(this).parent().children().index(this);
        var tmp_node = $("<div>"+$(this).parent().html()+"</div>");
        tmp_node.children().not(tmp_node.children().eq(index)).remove();
        var up = tmp_node.html();
        return up;
      }
    });
        function getcode(){
            $("#codebox").val($(".select").outerHTML());
        }
    </script>
    <div>
        <div>good</div>
        <div class="select">
        <!-- <script>.....<script> 这部分无法获取,原因可能是$(this).clone()是jquery方法不能克隆js-->
            <script>                    
            function hello(){
            alert("hello world");
            }
            </script>
            <ul>
                <li>ggg</li>
            </ul>
            <span>jjj</span>
        </div>
        <div>hello</div>
    </div>
    <textarea id="codebox" style="width:100%;height:300px"></textarea>
    <button onclick="getcode()">get it</button>