看看这个简单的 HTML:
<div id="wrap1">
  <iframe id="iframe1"></iframe>
</div>
<div id="warp2">
  <iframe id="iframe2"></iframe>
</div>
比方说,我想提出的面纱,以便#wrap2将之前#wrap1。iframe 被 JavaScript 污染了。我知道 jQuery.insertAfter()和.insertBefore(). 但是,当我使用它们时,iFrame 会丢失所有的 HTML 以及 JavaScript 变量和事件。
假设以下是 iFrame 的 HTML:
<html>
  <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
      // The variable below would change on click
      // This represents changes on variables after the code is loaded
      // These changes should remain after the iFrame is moved
      variableThatChanges = false;
      $(function(){
        $("body").click(function(){ 
          variableThatChanges = true; 
        });
      });
    </script>
  </head>
  <body>
    <div id='anything'>Illustrative Example</div>
  </body>
</html>
在上面的代码中,variableThatChanges如果用户点击身体,变量会...改变。此变量和点击事件应在 iFrame 移动后保留(以及已启动的任何其他变量/事件)
我的问题如下:使用 JavaScript(使用或不使用 jQuery),我如何移动 DOM(及其 iframe 子项)中的 wrap 节点,以便 iFrame 的窗口保持不变,并且 iFrame 的事件/变量/等保持不变相同的?