0

我需要在页面加载开始时运行一个函数,但它根本不起作用。我有一个父 HTML(称为 main)和三个框架(子 frameA、frameB、frameC)。

主.html:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <script type="text/javascript" src="js/main.js"></script>
    <title></title>
    </head>
    <frameset cols="40%,*">
    <frameset rows="55%,45%">
            <frame src="frameA.html" name="frameA" id="frameA" />
            <frame src="frameB.html" name="frameB" id="frameB" />
        </frameset>
            <frame src="frameC.html" name="frameC" id="frameC" />
    </frameset>
    </html>

框架A、B、C:

    <!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 content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <title>FrameA</title>
    </head>
    <body>
    <h1>FRAME A</h1>
    </body>
    </html>

和 main.js:

    function resetC() {
        var oFrame = document.getElementById('frameC');
        oFrame.document.write("Frame C reseted");
    }
    resetC();

我厌倦了“oFrame 为空”。为什么会这样?

4

1 回答 1

0

将 js 脚本移到框架集下方,它应该可以工作......

就在结束标签之前...

我认为这是因为文档已加载到您的 js 可以看到框架元素的位置...

于 2013-11-10T02:44:43.460 回答