<script type="text/javascript" language="javascript"> function attach() { //為按鈕注冊(cè)事件 document.getElementById("AA").onclick = function() { alert("A按鈕注冊(cè)事件!") }; document.getElementById("BB").attachEvent("onclick", click); document.getElementById("CC").attachEvent("onclick", function() { alert("C按鈕注冊(cè)事件"); }); } function click() { alert("B按鈕注冊(cè)事件"); } </script> </head> <body> <input type="button" value="test" onclick="attach()" /> <input type="button" value="AA" id="AA" /> <input type="button" value="BB" id="BB" /> <input type="button" value="CC" id="CC" /> </body> |
|