<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
div {
width: 200px;
height: 200px;
background: red;
margin: 0 auto;
}
</style>
<script type="text/javascript">
window.onload = function() {
document.getElementById('touch').ontouchmove = function(e) {
console.log(e.type);
};
document.getElementById('touch').ontouchend = function(e) {
console.log(e.type);
};
document.getElementById('touch').onclick = function(e) {
console.log(e.type);
};
document.getElementById('touch').ontouchstart = function(e) {
console.log(e.type + ';' + e.target.nodeName );
};
}
</script>
</head>
<body>
<div id="touch"></div>
</body>
</html>
JQuery 强迫症患者
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta charset="UTF-8" />
<script type="text/javascript" src="jquery-2.1.4.min.js" ></script>
<title>Document</title>
<style type="text/css">
div {
width: 200px;
height: 200px;
background: red;
margin: 0 auto;
}
</style>
<script type="text/javascript">
$( function() {
$("#touch").get(0).ontouchmove = function(e) {
console.log(e.type);
};
$("#touch").get(0).ontouchend = function(e) {
console.log(e.type);
};
$("#touch").get(0).onclick = function(e) {
console.log(e.type);
};
$("#touch").get(0).ontouchstart = function(e) {
console.log(e.type + ';' + e.target.nodeName );
};
})
</script>
</head>
<body>
<div id="touch"></div>
</body>
</html>