先看下这里的运行效果
http://www.izhaoyang.com/test/main.htm运行两次完全相同的alert(),显示却不一样,我不明白请高手赐教,也可以通过qq联系我,411908279

解决方案 »

  1.   

    main.htm
    <?xml version="1.0" encoding="UTF-8"?>
    <!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=utf-8" /> 
    <title>Main</title>
    <script type="text/javascript">
      <!-- <![CDATA[
      var G = "Main.htm";
      // ]]> -->
    </script>
    </head><body topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0">
    <iframe id="top" name="top" src="Top.htm" width="100%" height="20%"></iframe>
    <iframe id="left" name="left" src="Left.htm" width="20%" height="80%"></iframe>
    <iframe id="page" name="page" src="Page.htm" width="80%" height="80%"></iframe>
    <script type="text/javascript">
      <!-- <![CDATA[
      alert(frames[0].G);
      alert(frames[0].G);
      // ]]> -->
    </script>
    </body>
    </html>top.htm
    <?xml version="1.0" encoding="UTF-8"?>
    <!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=utf-8" /> 
    <title>标题</title>
    <script type="text/javascript">
      <!-- <![CDATA[
      var G = "Top.htm";  var $ = function(ID) {
        return document.getElementById(ID);
      };
      // ]]> -->
    </script>
    </head><body>
    <label id="label1">label1</label><br />
    <label id="label2">label2</label><br />
    <label id="label3">label3</label>
    </body>
    </html>left.htm
    <?xml version="1.0" encoding="UTF-8"?>
    <!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=utf-8" /> 
    <title>Left</title>
    <script type="text/javascript">
      <!-- <![CDATA[
      var G = "Left.htm";
      // ]]> -->
    </script>
    </head><body>
    </body>
    </html>page.htm
    <?xml version="1.0" encoding="UTF-8"?>
    <!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=utf-8" /> 
    <title>标题</title>
    <script type="text/javascript" src="Bounce.js"></script>
    <script type="text/javascript">
      <!-- <![CDATA[
      var G = "Page.htm";  window.onerror = function(msg, url, line) {
        alert(url +
              "\n____________________________________________________________" +
              "\n\nLine:" + line +
              "\nError:" + msg);
        return true;
      };  (function() {
        var _start = new Date();
        function _elapsed() {
          var now = new Date();
          var elapsed = Math.round((now - _start) / 1000);
          window.defaultStatus = "You have wasted " + elapsed + " second.";
        }
        setInterval(_elapsed, 1000);
      })();
      // ]]> -->
    </script>
    </head><body>
    <button onclick="Bounce.start()">开始</button>
    <button onclick="Bounce.stop()">停止</button>
    </body>
    </html>
      

  2.   

    <script type="text/javascript">
      <!-- <![CDATA[
      alert(frames[0].G);
      alert(frames[0].G);
      // ]]> -->
    </script>
    这里运行的2次alert()结果不一样,如果按下边这么运行都有返回值
    <script type="text/javascript">
      <!-- <![CDATA[
      alert(G);
      alert(frames[0].G);
      // ]]> -->
    </script>
    不知道是那里出问题了,请高手赐教。
      

  3.   

    自己解决了...突然想起书上说,在HTML文档还没有载入完成的时候并不稳定,所以试了下这么写就成功了window.onload = function() {
      alert(frames[0].G);
    }