首先,这两个页面(Main和iframe)应该来自同一个域,否则会引发跨域错误。
第1页
<html><head>
<script>
function delegate() {
var iframe = document.getElementById("myIframe");
iframe.contentWindow.change();
}
</script></head><body>
<iframe id="myIframe" src="box.html" height="25px" width="100px"></iframe>
<label for="box" onclick="delegate()">
Click Here.
</label></body></html>
第2页
<html><head>
<script>
function change() {
document.getElementById('box').checked = !document.getElementById('box').checked;
}
</script></head><body>
<input type="checkbox" id="box"></body></html>