jquery獲得同源iframe內body下標籤的值的方法,jqueryiframe

來源:互聯網
上載者:User

jquery獲得同源iframe內body下標籤的值的方法,jqueryiframe

test.html

Html代碼

<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery</title> <style type="text/css"> </style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function (){ $("#show").click(function (){ var iframeObj = $(window.frames["iframe_name"].document); alert(iframeObj.find("#un").val()); }); }); </script> </head> <body> <input type="button" id="show" value="show" /> <iframe id="iframe_id" name="iframe_name" src="http://localhost/test/login.html"></iframe> </body> </html>

login.html

Html代碼

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登入頁面</title> </head> <body> <form method="POST" action="#"> 使用者名稱:<input id="un" type="text" name="username" value="123d" /> 密 碼:<input type="text" name="password"/> <input type="submit" value="提交"> </form> </body> </html>

注意:必須同源


Jquery怎擷取iframe裡面body的html?

如果是自己網頁的話,可以這樣,$("iframe").contents().find("body").html();
意思是,擷取iframe裡面頁面body的內容
同理,$("iframe").contents().find("body").height();擷取高度,以此類推
希望可以幫到你,不懂可以問我
 
怎用jquery擷取iframe中的內容

架構代碼怎麼會寫到body裡頭去了,應該放到body外面,將body標籤放到noframes標籤裡面,然後寫上 $(window.frames['header'].document.body).html()
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.