有两个页面,属于父子关系,代码如下:
父页面
<html>
<head>
<title>父页面</title>
<script>
var tmp = "Test1";
</script>
</head>
<frameset>
<frame src="1.htm"/>
</frameset>
</html>
子页面
<html>
<head><title>子页面</title>
</head>
<body>
访问父页面变量:
<script>
try{document.write(tmp);}catch(e){document.write(e.message);}
</script></body>
</html>这样访问父页面的变量会产生异常。我知道加上parent.tmp会正常。
那么,如果不加parent,应该怎样解决。
建议我加parent的请勿扰
父页面
<html>
<head>
<title>父页面</title>
<script>
var tmp = "Test1";
</script>
</head>
<frameset>
<frame src="1.htm"/>
</frameset>
</html>
子页面
<html>
<head><title>子页面</title>
</head>
<body>
访问父页面变量:
<script>
try{document.write(tmp);}catch(e){document.write(e.message);}
</script></body>
</html>这样访问父页面的变量会产生异常。我知道加上parent.tmp会正常。
那么,如果不加parent,应该怎样解决。
建议我加parent的请勿扰
parent还可以直接引用Object类型的,其他方式的就悲催了。
另外:既然楼主知道加parent 干嘛非给自己找刺激?直接说你的出发点就是了 不用卖关子 ^_^
父页面是自己写的。不想去修改子页面,
那样你可以直接调用
这样有什么不妥吗