2

iframeを使用して CI プロジェクトに html ページを追加します。今、含まれているページから最初の div を削除したいと思います。そのdivのIDはありません。私はjqueryコードを書きますが、iframe全体を削除します。ここにあります

$(document).ready(function(){
  $("iframe").load(function(){
    //$('div:first').remove(); 
      $("body").find("div:first-child").remove();   
  });
}); 

html

<div class="span12">
                <iframe id="patrolIframe" width="100%" height="900" frameborder="0" scrolling="yes" allowtransparency="true" 
                src="http://...../map.html"></iframe>
            </div>
4

3 に答える 3

2
$(document).ready(function(){
  $("iframe").load(function(){
      $('div')[0].remove(); 
     });
}); 
于 2013-04-16T10:55:18.867 に答える
0

試す

$(document).ready(function(){
  $("iframe").load(function(){
    //$('div:first').remove(); 
      $(this).find("div:first-child").remove();   
  });
});

$("body") セレクターは、jquery が読み込まれるページの本文、つまりページ全体を選択します。iframe がそのページの最初の div 内にあると推測しているため、削除されます。私は iframe を使用しませんが、その場合の $(this) は iframe を参照していると想定しているため、機能するはずです。

于 2013-04-16T10:54:46.753 に答える