直接上代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JavaScript事件</title> <script> function changeColor() { document.getElementById("test").style.background="#98F5FF"; } </script> <style type="text/css"> #test { background-color: #CD96CD; width: 100px; height: 100px; border-radius: 50px; } </style> </head> <body> <p>点击圆球,改变颜色</p> <div id="test" onclick="changeColor()"></div> </body> </html>