<script src="js/jQuery 1.6.2.js" type="text/javascript"></script>
</head>
<script>
$(function(){

$("button").click(function(){
//$("p").contents().not("[nodeType=1]").wrap("<b/>");
//var b=$("p").contents("a").attr("href");
//$("iframe").contents("a").append("I'm in an iframe!");
$("iframe").contents().find("body").append("I'm in an iframe!");
//alert(b);
   })
   
   })
</script>
<body>
<iframe src="index-blank.html" width="300" height="100"></iframe>
<p>Hello <a href="http://ejohn.org/">John</a>, how are you doing?</p>
<button>aa</button>
</body>
</html>

解决方案 »

  1.   

    $($("iframe:first")[0].contentWindow.document.body).append("I'm in an iframe!");
    试试 。
      

  2.   

    我FF7 ,CHROME 14 ,IE8都可以 。
    jquery用的1.4.2 。
      

  3.   

    就是1楼的代码<html>
      <head>
      <title></title>
        <script src="jquery-1.6.4.min.js" type="text/javascript"></script>
        <script>
    $(function(){$("button").click(function(){
    //$("p").contents().not("[nodeType=1]").wrap("<b/>");
    //var b=$("p").contents("a").attr("href");
    //$("iframe").contents("a").append("I'm in an iframe!");
    //$("iframe").contents().find("body").append("I'm in an iframe!");
    $($("iframe:first")[0].contentWindow.document.body).append("I'm in an iframe!");
    //alert(b);
    })
     
    })
    </script>
      </head>
      
      <body>
      <iframe src="index-blank.html" width="300" height="100"></iframe>
    <p>Hello <a href="http://ejohn.org/">John</a>, how are you doing?</p>
    <button>aa</button>
      </body>
    </html>
      

  4.   


    你正确引用的JQuery了吗?
      

  5.   

    应用了
    $("button").click(function(){
    //$("p").contents().not("[nodeType=1]").wrap("<b/>");
    var b=$("p").contents("a").attr("href");
    //$("iframe").contents("a").append("I'm in an iframe!");
    //$("iframe").contents().find("body").append("I'm in an iframe!");
    //$($("iframe:first")[0].contentWindow.document.body).append("I'm in an iframe!");
    alert(b);
    })
    试过这样都能弹出警告框
      

  6.   

    $($("iframe:first").get(0).contentWindow.document.body).html("I'm in an iframe!");