【问题标题】:How to change the iframe's component's value right after the iframe src change?如何在 iframe src 更改后立即更改 iframe 组件的值?
【发布时间】:2012-05-04 17:17:45
【问题描述】:

最初 iframe src 是 3.html 并且它没有 id 为 'p' 的元素,我想将 iframe src 更改为 2.html 并将 'p' 元素值更改为 11。但它没有不行。谁能给出一些解决方案?

我想做的事情很简单:

1)更改 iframe src。

2) 更改 iframe 的元素值。

1.html

<script type="text/javascript">
function testIframe()
{
test1();
test2();

}
function test1()
{
document.frames('myFrame').src='2.html';
}
function test2()
{
document.frames('myFrame').document.getElementById('p').innerHTML='11';
}
</script>
<body>
<input type="submit" id="button" onClick="testIframe()" value="ok">
<iframe name="myIFrame" id="myFrame" src="3.html">
</body>

2.html

<body>
<p id="p">33</p>
</body>

3.html

<body>
</body>

【问题讨论】:

    标签: javascript html iframe


    【解决方案1】:

    在 iframe 上连接一个 ONLOAD 事件。您需要这样做,因为您只能在页面加载后更改该值。在事件处理程序中,查看 SRC,如果它是正确的页面,则运行您的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-02
      • 1970-01-01
      • 1970-01-01
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多