我有2個HTML文檔:1個主文檔,其中有一個iframe,顯示第二個HTML頁面。使用jquery從外部從iframe中讀取內容
我想從父文檔訪問iframe的內容。我試過使用find()
和contents()
,但它不適合我。
這是我的代碼:
主文檔
<!DOCTYPE html>
<html>
<head>
<script src="./js/gjquery.js"></script>
<script type="text/javascript">
$(function(){
$('#123').click(function(){
alert("Testing...");
var v = $('#frameDemo').contents().find('body').html();
alert(v);
});
})
</script>
</head>
<body>
<button id="123" >mad</button>
<iframe src="./1.htm" width="80%" height="20%" id='frameDemo'></iframe>
</body>
iframe的文檔
<html>
<head></head>
<body>
<p>Hello <a href="http://ejohn.org/">John</a>, how are you doing?</p>
<table width="700" border="1" id="test">
<tr><td>g</td><td>ggg</td></tr>
<tr><td>g</td><td>ggg</td></tr>
<tr><td>g</td><td>ggg</td></tr>
</table>
<p>Hello world!</p>
<div id="someID">Hello world!</div>
</body>
</html>
find()
也未實施R剔除任何結果,無論我嘗試使用哪個選擇器。
我看到錯字'/ js/gjquery.js'。和控制檯是你的朋友,開始使用它 – Peter 2013-02-08 17:25:43
你能看到你的'測試'警報? – 2013-02-08 17:26:55
是的......甚至顯示另一個警報..但它來undefined – 2013-02-08 17:36:30