在 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>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP