如果想在父窗口example.htm中控制自窗口test.htm中的元素:
下面代码copy到example.htm中
<Iframe src="test.htm" id="test" width="250" height="200" scrolling="no" frameborder="0"></iframe >
<script>
function a(){
document.all.test.contentWindow.document.all.myH1.innerText="to be sucessful"
}
</script>
<input type=button onclick="a()" value="修改myH1的值">
下面代码copy到example.htm中
<Iframe src="test.htm" id="test" width="250" height="200" scrolling="no" frameborder="0"></iframe >
<script>
function a(){
document.all.test.contentWindow.document.all.myH1.innerText="to be sucessful"
}
</script>
<input type=button onclick="a()" value="修改myH1的值">
function a(){
document.all["test"].contentWindow.myH1.innerText="hello"
}
test.htm文件代码为:
< html >
< body >
< h1 id="myH1" >hello,my boy< /h1 >
< /body >
< /html >test.myH1.innerText="hello,my dear";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
注意看,我把id改为name……