曲径通幽论坛

标题: 对框架引用的两种方式(框架名 与 frames[] 数组) [打印本页]

作者: easy    时间: 2013-4-25 15:24
标题: 对框架引用的两种方式(框架名 与 frames[] 数组)
对框架引用主要有两种方式,一种是通过框架名,一种是通过 frames[] 数组。

通过框架名

<html>
<head>
  <title>通过框架名引用框架</title>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">

</head>
<body>
    <iframe name="Frame1" width="300" height="200"> </iframe> <br><br>
    <iframe name="Frame2" width="300" height="200"> </iframe> <br><br>
  
    <script type="text/javascript" language="javascript">
    <!--
        window.Frame1.document.write("欢迎访问");
        window.Frame2.document.write("www.groad.net");
     -->
     </script>

</body>

</html>
输出效果:
[attach]1556[/attach]

通过 frames[] 数组的方式

<html>
<head>
  <title>frames[] 数组引用框架</title>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">

</head>
<body>
    <iframe name="Frame1" width="300" height="200"> </iframe> <br><br>
    <iframe name="Frame2" width="300" height="200"> </iframe> <br><br>
    <iframe name="Frame3" width="300" height="200"> </iframe> <br><br>
    <iframe name="Frame4" width="300" height="200"> </iframe> <br><br>
    <script type="text/javascript" language="javascript">
    <!--
        for (var i = 0; i < window.frames.length; i++)
            window.frames[i].document.write("第", i+1, "个框架的内容");
        
     -->
     </script>

</body>

</html>
效果:
[attach]1557[/attach]




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2