frames对象
2025年4月30日小于 1 分钟
示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>frames 对象</title>
</head>
<body>
<iframe src="./frames1.html" frameborder="1"></iframe>
<iframe src="./frames2.html" frameborder="1"></iframe>
<iframe src="./frames3.html" frameborder="1"></iframe>
<script type="text/javascript">
window.onload=function()
{
frames[1].document.getElementsByTagName('body')[0].style.background = 'black';
}
</script>
</body>
</html>
辅助示例代码
frames1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body style='background:blue'>
11111111111111
</body>
</html>
frames2.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body style='background:orange'>
22222222222222
</body>
</html>
frames3.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body style='background:green'>
33333333333333
<script type="text/javascript">
//第一种方法 最近的上一层及
//parent.document.getElementsByTagName('body')[0].style.background = 'yellow';
//第二种方法 最顶级(因为本例只有一层)
top.document.getElementsByTagName('body')[0].style.background = 'yellow';
</script>
</body>
</html>