父窗口如何给子窗口绑定点击事件

父窗口怎么给子窗口绑定点击事件
父页面:a.htm

<!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>a</title>
<script type="text/javascript">
function alert_(){
var iframe=document.getElementById("frame").contentWindow;
alert(iframe.document.getElementById("div").innerHTML);
}

function update_(){
var iframe=document.getElementById("frame").contentWindow;
iframe.document.getElementById("div").innerHTML="七上八下";
}

//给b页面绑定点击事件    这里为什么不行呢。。。  求解决
var button=document.getElementById("frame").contentWindow.document.getElementById("button2");
button.click=function(){
alert("555555555");
}

</script>
</head>

<body>
<div>
<input type="button" value="弹出iframe中div的值" onclick="alert_()" id="button1"/>
<input type="button" value="修改iframe中div的值" onclick="update_()"/>
</div>
<iframe src="b.html" frameborder="1" width="600" height="100" style="border:#F00" id="frame"/>
</body>
</html>



子窗口:b.html

<!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>b</title>
</head>
<body>
<input type="button" id="button2" value="修改a中的弹出按钮的值"/>
<div id="div" style=" border:1px solid yellow;">乱七八糟</div>
</body>
</html>


问题在a.html  17行。。。
------解决思路----------------------
引用:
Quote: 引用:

1.在加载完后再执行
2.是button.onclick=function(),不是button.click=function()
<!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>a</title>
<script type="text/javascript">
    function alert_(){
        var iframe=document.getElementById("frame").contentWindow;   
        alert(iframe.document.getElementById("div").innerHTML);
    }
     
    function update_(){
        var iframe=document.getElementById("frame").contentWindow;   
        iframe.document.getElementById("div").innerHTML="七上八下";
    }
    function doit(){
    //给b页面绑定点击事件    这里为什么不行呢。。。  求解决
    var button=document.getElementById("frame").contentWindow.document.getElementById("button2");
    button.onclick=function(){
        alert("555555555");   
    }
    }
     
</script>
</head>
 
<body onload="doit()">
<div>
<input type="button" value="弹出iframe中div的值" onclick="alert_()" id="button1"/>
<input type="button" value="修改iframe中div的值" onclick="update_()"/>
</div>
<iframe src="b.html" frameborder="1" width="600" height="100" style="border:#F00" id="frame"/>
</body>
</html>


你好,像这样写也是不行。。

---------------------------------------------------
你拷贝我的代码啊,我运行测试过的没有问题。