论坛首页 入门讨论版 JavaScript

iframe中的数据传到parent窗口后,数据类型检测异常

浏览 136 次
该帖已经被评为新手帖
作者 正文
最后更新时间:2008-05-20
有这样两个页面: a.htm
<html>
<head>
<script>
function f1( p)
{
		 alert (  " type is "+ typeof p);
		alert( " is Object :" + ( p instanceof Object));
		alert( " is Array : " + ( p instanceof Array));


}

function test()
{
		var f= document.frames("frame1");
        var p= f.getData();
		f1( p);

}

</script>
</head>

<body>
<input type="button"  value="test"  onclick="test();">
<iframe  id=frame1  width="100%" height="200"  src="b.htm"></iframe>
</body>
</html>



页面 b.htm
<html>
<head>
<script>
function getData(  )
{ 
         var  p=[];
		 p[p.length]='abc';
		 p[p.length]='def';

		alert (  " type is "+ typeof p);
		alert( " is Object :" + ( p instanceof Object));
		alert( " is Array : " + ( p instanceof Array));
        return p;
}
 
</script>
</head>

<body>
     a   iframe 
</body>
</html>


用浏览器打开 a.htm ,点击其中的 test按钮, 大家看一下提示信息,相当奇怪。 分别是:
type is object
is Object: true
is Array :true

type is object
is Object: false
is Array :false

为什么对象做为参数传给parent窗口后,类型检测会出现不同的结果。 
   
论坛首页 入门讨论版 JavaScript

跳转论坛:
JavaEye推荐