答案 0 :(得分:1)
我总是使用这样的东西
var touchdevice = ('ontouchstart' in window);
var START_EVENT = touchdevice ? 'touchstart' : 'mousedown';
var MOVE_EVENT = touchdevice ? 'touchmove' : 'mousemove';
var END_EVENT = touchdevice ? 'touchend' : 'mouseup';
在像这样的代码中使用它:
$('#something1').on(START_EVENT, function (event) {
dosomething1(event);
});
$('#something2').on(END_EVENT, function (event) {
dosomething2(event);
});
$('#something3').on(MOVE_EVENT, function (event) {
dosomething3(event);
})
这将在“鼠标”和“触摸”事件之间自动切换