JS案例:使用动态绑定显示问候语
来自CloudWiki
<!doctype html> <html> <head> <meta charset="utf-8"> <title>动态绑定事件示例</title> <script type="text/javascript"> function wel_girl() { alert("欢迎您,女士请到二楼接待室!"); } function wel_boy() { alert("欢迎您,男士请到一楼接待室!"); } </script> </head> <body> <p> <button name="button1" id="button1">我是男士</button> </p> <p> <button name="button2" id="button2">我是女士</button> </p> <script type="text/javascript"> var welcome_boy=document.getElementById("button1"); welcome_boy.onclick=wel_boy; var welcome_girl=document.getElementById("button2"); welcome_girl.onclick=wel_girl; </script> </body> </html>