javascript中top的作用
2008-02-03 09:49
351 查看
top作用是取得最顶层框架对象
A.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>prototype test</title>
</head>
<body>
<iframe src="b.html"></iframe>
<script language="javascript">...
var topstr = "my top";
alert(a.html='+top.location.href);
</script>
</body>
</html>B.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>prototype test</title>
</head>
<body>
<iframe src="c.html"></iframe>
<script language="javascript">...
alert('b.html='+top.location.href+";a.html.topstr="+top.topstr);//top.topstr可取a.html(顶层框架参数)的topstr变量
</script>
</body>
</html>
C.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>prototype test</title>
</head>
<body>
<script language="javascript">...
alert('c.html='+top.location.href+";a.html.topstr="+top.topstr);//top.topstr可取a.html(顶层框架参数)的topstr变量
</script>
</body>
</html>
b.html中的top=parent c.html中的top=parent.parent
A.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>prototype test</title>
</head>
<body>
<iframe src="b.html"></iframe>
<script language="javascript">...
var topstr = "my top";
alert(a.html='+top.location.href);
</script>
</body>
</html>B.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>prototype test</title>
</head>
<body>
<iframe src="c.html"></iframe>
<script language="javascript">...
alert('b.html='+top.location.href+";a.html.topstr="+top.topstr);//top.topstr可取a.html(顶层框架参数)的topstr变量
</script>
</body>
</html>
C.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>prototype test</title>
</head>
<body>
<script language="javascript">...
alert('c.html='+top.location.href+";a.html.topstr="+top.topstr);//top.topstr可取a.html(顶层框架参数)的topstr变量
</script>
</body>
</html>
b.html中的top=parent c.html中的top=parent.parent
相关文章推荐
- javascript中top的作用
- JavaScript作用域、上下文、执行期上下文、作用域链、闭包
- 一个简单的javascript小程序学习javascript作用域和局部变量提前声明
- javascript 函数及作用域总结介绍
- Javascript学习笔记3――作用域
- javascript中不存在块级作用域,所以要小心使用在块级作用域中的函数声明所带来的作用域混乱.
- 深入理解javascript作用域系列第四篇——块作用域
- 浅析JavaScript作用域链
- JavaScript中有一个call和apply方法,其作用基本相同,但也有略微的区别
- JavaScript之--引用类型、作用域、 基本包装类型、内置对象Math
- JavaScript 开发进阶:理解 JavaScript 作用域和作用域链
- 杂记——彻底认清javascript中的作用域问题
- 深入理解javascript原型和闭包(13)-【作用域】和【上下文环境】
- js教程:javascript作用域(Scope)
- javascript作用域
- JavaScript scrollTop
- JavaScript 的 作用域----个人理解
- javascript:void(0); 的作用
- javascript : style.top, clientTop, offsetTop, scrollTop 等示意图
- JavaScript的作用域、块级作用域(私有作用域)概念理解