<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>长按</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<meta name="apple-touch-fullscreen" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes" />
<link href="css/travelstyle.css" rel="stylesheet" type="text/css" />
</head>
<body id="body_id" >
<div style="width:100%;">
<div style="width:100%; height:100px; background-color:#CCC;" ontouchstart="gtouchstart()" ontouchmove="gtouchmove()" ontouchend="gtouchend()">长按我</div>
</div>
<script>
var timeOutEvent=0;
function gtouchstart(){
timeOutEvent = setTimeout("longPress()",500);
return false;
};
function gtouchend(){
clearTimeout(timeOutEvent);
if(timeOutEvent!=0){
alert("你这是点击,不是长按");
}
return false;
};
function gtouchmove(){
clearTimeout(timeOutEvent);
timeOutEvent = 0;
};
function longPress(){
timeOutEvent = 0;
alert("长按事件触发发");
}
</script>
</body>
</html>