代码示例:(标识:eg_js_events_onmousedown_1)
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction(elmnt, clr) {
  elmnt.style.color = clr;
}
</script>
</head>
<body>

<p onmousedown="myFunction(this,'red')" onmouseup="myFunction(this,'green')">
单击文本以更改颜色。按下鼠标按钮时会触发带参数的函数,当释放鼠标按钮时,会再次使用其他参数触发。
</p>

</body>
</html>
运行结果: