使用 onMouseDown 和 onMouseUp 侦听器来更改用户单击按钮时的样式。
<!DOCTYPE html>
<html>
<head>
<style>
.button, .button_clicked {
position:absolute;
left:50%;
top:50%;
width:200px;
height:200px;
margin-left:-100px;
margin-top:-100px;
background-color:#F00;
border-style:outset;
border-color:#F88;
border-width:7px;
}
.button_clicked {
border-style:inset;
background-color:#C00;
}
</style>
</head>
<body>
<div class="button"
onmousedown="this.className='button_clicked'"
onmouseup="this.className='button'"
onmouseout="this.onmouseup()"
onclick="alert('You clicked me')"
></div>
</body>
<script>
</script>
</html>