- 相關(guān)推薦
JS操作iframe里的dom實(shí)例解釋
直接賦值如下代碼測試即可明白:
1.html:
復(fù)制代碼 代碼如下:
====================注意:測試從這里開始=========================
用來測試子窗體iframeA訪問父窗體的某元素
====================iframe分割線=========================
====================iframe分割線=========================
先來演示:父窗體訪問子窗體中的某方法或元素
總結(jié):父窗體訪問子窗體的方法跟元素采用不同的方式
//子窗口訪問父窗口方法
function testP(ss){
alert(ss)
}
//取得iframe的元素
function getIframe(id){
return document.getElementById(id).contentWindow.document;
}
//父窗口訪問子窗口元素
function frameDiv(){
getIframe("frameA").getElementById("ooxx").style.backgroundColor="#f00"
//window.frames["iframeA"].getElementById("ooxx").style.backgroundColor="#f00" //不能通過這種形式訪問某元素
}
//父窗口訪問子窗口方法
function frameFun(){
//getIframe("frameB").getsFun();//不能通過這種形式訪問子窗體某方法
// window.frames["iframeB"].getsFun();
alert(window.frames["iframeB"].getsFun());
}
a.html
復(fù)制代碼 代碼如下:
用來測試父窗體訪問子窗體中的某元素
用來測試子窗口B訪問窗體A的某元素
1.子窗口iframeA訪問父窗口的某元素
//子窗口訪問父窗口的某元素
function frameToPdiv(){
parent.document.getElementById("pox").style.color="#fff";
parent.document.getElementById("pox").style.backgroundColor="#f0a0f0"
}
//子窗口訪問父窗口方法
function frameToPfun(ss){
parent.testP("ssss");
}
//用于測試iframeB訪問的方法
function testBA(){
alert("用于測試iframeB訪問的方法")
}
b.html
復(fù)制代碼 代碼如下:
二:測試子窗體間相互訪問某方法或元素
//子窗體B訪問子窗體A的某元素
function frameTframeDiv(){
//parent.document.getElementById("frameA").contentWindow.document.getElementById("divooxx").style.color="#a0c0f0";
//parent.document.getElementById("frameA").contentWindow.document.getElementById("divooxx").style.backgroundColor="#000"
var _bframe=parent.getIframe("frameA");//子窗體訪問父窗體方法
_bframe.getElementById("divooxx").style.color="#a0c0f0";
_bframe.getElementById("divooxx").style.backgroundColor="#000";
}
//子窗體B訪問子窗體A的某方法
function frameTframeFun(){
window.parent.frames["frameA"].testBA();
}
function getsFun(){
return "sssssss";
}
//getFun()
【JS操作iframe里的dom實(shí)例解釋】相關(guān)文章:
硬盤邏輯故障解決方法實(shí)例07-16
excel中驗(yàn)算公式使用實(shí)例介紹12-08
象棋的術(shù)語解釋08-14
焊工有哪些操作規(guī)程-焊工的操作規(guī)程04-02
公文寫作四個(gè)技巧及實(shí)例10-14
電腦常用操作技巧07-19
買殼上市操作流程04-04
excel表格的基本操作08-11
象棋的下法口訣及解釋04-12