1.html
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
 function th() {
        window.open("2.html", "退货", "with=700px,height=530px,top=0");
    }
</script>
<div id="div1"></div>
<input type="button" value="click me" onclick="th()" />2.html<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#fz").click(function() {
var $aa=$("#di").clone(true);//.appendTo($("#di2")); 
alert($aa);
$(window.opener.document.body).children("#div1").append($aa); 
  });
});</script>
<div id="di">asdfadsfa</div>
<input id="fz" type="button" value="clone" onclick="cl()" />我主要想将open的页面所克隆的东西父级能够接收并显示出来。但是似乎
$(window.opener.document.body).children("#div1").append("dfasdfa");就可以,
以上这句$(window.opener.document.body).children("#div1").append($aa); 就不行了。
要是有其他方法,不妨告诉小弟。谢谢。

解决方案 »

  1.   

    你如果想追加的只是di的内容,那不需要使用clone()呀
    $(window.opener.document.body).children("#div1").append($("#di").html());
      

  2.   

    对于以下按钮,你已经使用$("#fz").click(function() {}绑定了事件,下面的onclick就不要写了,再说,你也找不到这个函数呀
    <input id="fz" type="button" value="clone" onclick="cl()" />
    改为
    <input id="fz" type="button" value="clone"/>
      

  3.   

    补充下。楼上的语句似乎对于html有效,要是两个aspx之间似乎失效了。不知原因为何?
      

  4.   

    aspx在服务器端解析之后,照样是纯html格式的文档。没这个说法要有就可能是你用法出现了问题。我测试是无误的
      

  5.   

      <form id="form1" runat="server">我发现就因为多了这个才失效的
      

  6.   

    你如果连按钮也是服务器控件生成的,那可能ClientID才会有效。你自己右键看一下页面源文件,看看那些div呀,按钮呀。id是不是与你绑定的一样就知道了你不会连这个都没确定吧?事件有没有绑定上你至少得确定吧?
      

  7.   

    1.html
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script>
     function th() {
      window.open("2.html", "退货", "with=700px,height=530px,top=0");
      }
    </script>
    <form><div id="div1"></div>
    <input type="button" value="click me" onclick="th()" /></form>
    2.html
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script>
    $(document).ready(function() {
    $("#fz").click(function() {
    $(window.opener.document.body).children("#div1").append($("#di").html());
      });
    });</script>
    <div id="di">   <table id="myTable2" width="100%" cellpadding="0" cellspacing="0" border="1" bordercolor="#aca899" style="border-collapse:collapse" align=center> <tr>
       <td height="19px" style="background:#ebebeb">序号</td>
        <td height="19px" style="background:#ebebeb">商品条码</td>
        <td height="19px" style="background:#ebebeb">商品名称</td>
        <td height="19px" style="background:#ebebeb">单位</td>
        <td height="19px" style="background:#ebebeb">规格</td>
        <td height="19px" style="background:#ebebeb">生产厂商</td>
        <td height="19px" style="background:#ebebeb">单价</td>
           <td height="19px" style="background:#ebebeb">数量</td>
        <td height="19px" style="background:#ebebeb">批准文号</td>  </tr>
     
    </table> </div>
    <input id="fz" type="button" value="clone" />就这么写,1.html里添加多了一个form后就失效了。
      

  8.   

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script>
     function th() {
      window.open("2.html", "退货", "with=700px,height=530px,top=0");
      }
    </script><div id="div1"></div>
    <form>
    <input type="button" value="click me" onclick="th()" /></form>
    将div1移至form外面就可以了。。
      

  9.   

    $(window.opener.document.body).children("#div1").append($("#di").html());
    改成
    $(window.opener.document.body).find("#div1").append($("#di").html());试试
      

  10.   

    因为children()只查找指定对象的子元素而不是查找其所有后代元素
      

  11.   

    可以了,谢谢。
    问题是为啥加了form后用children就不行了呢
    因为children()只查找指定对象的子元素而不是查找其所有后代元素 不是很明白。能否简单再说明下呢?
      

  12.   

    直白点说:children()只查找指定对象下的一级子节点。举个最简单的例子吧
    <script>
    $(function(){
        $('#me').children().each(function(){
            alert($(this).attr("id"))
        })
    })
    </script>
    <div id="me">
    <form id="f1">
    <div id="d1"></div>
    </form>
    <div id="d2"></div>
    </div>对me来说,它的一级子节点就是id=f1的form和id=d2的div。id=d1的div是不包含在内的。它属于后代元素了