<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>
</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>
试试 。
jquery用的1.4.2 。
<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>
你正确引用的JQuery了吗?
$("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);
})
试过这样都能弹出警告框