使用php自動備份數據庫表的實現方法
772
2023-12-08
本文實例分析了jQuery取得iframe中元素的常用方法。分享給大家供大家參考,具體如下:
jquery取得iframe中元素的幾種方法:
在iframe子頁面獲取父頁面元素
代碼如下:
$('#objId', parent.document);
搞定...
在父頁面 獲取iframe子頁面的元素:
$("#objid",document.frames('iframename').document) $(document.getElementById('iframeId').contentWindow.document.body).html()
顯示iframe中body元素的內容。
$("#testId", document.frames("iframename").document).html();
根據iframename取得其中ID為"testId"元素
$(window.frames["iframeName"].document).find("#testId").html()
用JS或jQuery訪問頁面內的iframe,兼容IE/FF
注意:框架內的頁面是不能跨域的!
假設有兩個頁面,在相同域下.
index.html 文件內含有一個iframe:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>頁面首頁</title> </head> <body> <iframe src="http://www.gimoo.net/t/1903/iframe.html" id="koyoz" height="0" width="0"></iframe> </body> </html>
iframe.html 內容:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>iframe.html</title> </head> <body> <div id="test">www.gimoo.net</div> </body> </html>
1. 在index.html執行JS直接訪問:
document.getElementById('koyoz').contentWindow.document.getElementById('test').style.color='red'
此代碼已經測試通過,能支持IE/firefox .
2. 在index.html里面借助jQuery訪問:
$("#koyoz").contents().find("#test").css('color','red');
此代碼的效果和JS直接訪問是一樣的,由于借助于jQuery框架,代碼就更短了.
收集網上的一些示例:
用jQuery在IFRAME里取得父窗口的某個元素的值只好用DOM方法與jquery方法結合的方式實現了
1. 在父窗口中操作 選中IFRAME中的所有單選鈕
$(window.frames["iframe1"].document).find("input:radio").attr("checked","true");
$(window.parent.document).find("input:radio").attr("checked","true");
$(window.frames["iframe1"].frames["iframe2"].document).find("input:radio").attr("checked","true");
希望本文所述對大家jQuery程序設計有所幫助。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!