Contoh kecil acara Javascript:
Tukar warna div dengan mengklik butang
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>事件</title> <style type="text/css"> div{width:150px;height:150px;border:1px solid #f60;}</style> </head> <body> <div id="dv"></div><br> <input type="button" value="点击" onclick="bt()"> <script type="text/javascript"> function bt(){ var div=document.getElementById("dv"); div.style.backgroundColor="red"; } </script> </body> </html>