<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title></title>
</head>
<body>
<input id="p1" type="button" onmousedown="holdDown()" onmouseup="holdUp()" value="鼠标长按"/>
<script type="text/javascript">
var timeStart, timeEnd, time;
function getTimeNow() {
var now = new Date();
return now.getTime();
}
function holdDown() {
timeStart = getTimeNow();
time = setInterval(function () {
timeEnd = getTimeNow();
if (timeEnd - timeStart > 1000) {
clearInterval(time);
document.getElementById("p1").style.color = "red";
}
}, 100);
}
function holdUp() {
clearInterval(time);
}
</script>
</body>
</html>