源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> </head> <body> <p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()"> 点击这个文本,当鼠标按下文本被设置为红色,当鼠标抬起时文本被设置为绿色。 </p> <script> function mouseDown() { document.getElementById("p1").style.color = "red"; } function mouseUp() { document.getElementById("p1").style.color = "green"; } </script> </body> </html>
运行结果