日期:2014-05-16 浏览次数:20415 次
<html> <head> <script type = "text/javascript"> window.onload = function(){ var oFrame1 = document.getElementById("frame1"); alert(oFrame1.className); //输出left alert(oframes == window.frames[0]); //输出false,为什么会不相等?不是应该都是指第一个frame元素么? alert(window.frames.length); //输出2,说明有两个frame元素 alert(window.frames[0].className); //输出undefinded,为什么不是left? } </script> </head> <frameset rows = "50%,50%"> <frame id = "frame1" class = "left" src="./leftframe.html"> <frame class = "right" src="./rightframe.html"> </frameset> </html>
<html> <head> <script type = "text/javascript"> window.onload = function(){ var oFrame1 = document.getElementById("frame1"); alert(oFrame1 == window.frames[0].parent.document.getElementById("frame1")); //输出false,为什么会不相等?不是应该都是指第一个frame元素么? } </script> </head> <frameset rows = "50%,50%"> <frame id = "frame1" class = "left" src="./leftframe.html"> <frame class = "right" src="./rightframe.html"> </frameset> </html>
------解决方案--------------------
窗体window和元素怎么会一样呢,对象结构就不一样。