当使用 HTML 中的元素按下鼠标按钮时执行脚本?
在 HTML 中使用onmousedown属性可以在元素按下的鼠标按钮执行脚本。
示例
你可以试着运行以下代码,来实现onmousedown属性 -
<!DOCTYPE html> <html> <body> <h3 id = "myid" onmousedown = "mouseDown()" onmouseup = "mouseUp()"> This is demo heading. </h3> <p>Click above and then release.</p> <script> function mouseDown() { document.getElementById("myid").style.color = "yellow"; } function mouseUp() { document.getElementById("myid").style.color = "blue"; } </script> </body> </html>
广告