当前位置: 代码迷 >> JavaScript >> JS对iframe操作的有关问题(无法取到对象)
  详细解决方案

JS对iframe操作的有关问题(无法取到对象)

热度:32   发布时间:2012-02-21 16:26:23.0
JS对iframe操作的问题(无法取到对象)
<iframe   src= "about:blank "   id= "target "   width= "640 "   height= "480 "> </iframe>
<script   language= "javascript "   type= "text/javascript ">
if(document.all)
{
var   frm=window.frames[ "target "].document;
frm.onreadystatechange=function()
{
if(frm.readyState== "complete ")
{
frm.body.innerHTML= ' <form   method= "post "   name= "form1 "   target= "main "   id= "form1 "     > 加载了   为什么点击,确取不了对像 </form> ';
}
};
}
function   dd(){
var   ss=frames[ "target "].forms[ "form1 "];
alert   (ss)
}
</script>
<a   onclick= "dd() "> 点这里 </a>

大家帮我看看,为什么取不到对象。

------解决方案--------------------
<iframe src= "about:blank " name= "target " width= "640 " height= "480 "> </iframe>
<script language= "javascript " type= "text/javascript ">
if(document.all)
{
var frm=window.frames[ "target "].document;
frm.onreadystatechange=function()
{
if(frm.readyState== "complete ")
{
frm.body.innerHTML= ' <form method= "post " name= "form1 " target= "main " id= "form1 " > 加载了 为什么点击,确取不了对像 </form> ';
}
};
}
function dd(){
var ss=frames[ "target "].document.forms[ "form1 "].outerHTML;
alert (ss)
}
</script>
<a onclick= "dd() "> 点这里 </a>
  相关解决方案