javascript - 如何使用鼠标事件等触摸事件在移动设备中选择元素
问题描述
我有代码前时间表,用于选择当天的元素,它在带有鼠标事件的笔记本电脑设备中工作,但在移动设备中的触摸事件中不起作用,我有另一个问题图标,用于在桌面设备工作中关闭表单 onclick,但在移动笔记工作中使用 ontouch
ontouchstart="alert();" // work true; in mobile
ontouchstart="close();" // not working false; in mobile
onclick="close();" // work true; in desktop
close();//custom function
谢谢和对不起我的英语
var lundi = mytr[1].children, mardi = mytr[2].children, mercredi =
mytr[3].children,jeudi = mytr[4].children;
var l=1,m1=1,m2=1,j=1,v=1,s=1,aux;
flag = true;
if(m1 && m2 && j && v && s){
lundi[i].addEventListener('mousedown',function(event) {
down =true;
l=false;
HeurDebut = this.cellIndex;
});
lundi[i].addEventListener('mousemove',function(event) {
if (flag && down && m1 && m2 && j && v && s){
this.classList.add(color);
jour = "Lundi";
Njour = 1;
}
});
lundi[i].addEventListener('mouseup',function(event) {
flag = false;
HeurFin = this.cellIndex;
if(retemp){
sendTemp(HeurDebut,HeurFin,jour,Njour);
retemp = false;
}
form.style.display ="block";
});
}
//for mobile
flag = true;
if(m1 && m2 && j && v && s){
lundi[i].addEventListener('touchstart',function(event) {
down =true;
l=false;
HeurDebut = this.cellIndex;
});
lundi[i].addEventListener('touchmove',function(event) {
if (flag && down && m1 && m2 && j && v && s){
this.classList.add(color);
jour = "Lundi";
Njour = 1;
}
});
lundi[i].addEventListener('touchend',function(event) {
flag = false;
HeurFin = this.cellIndex;
if(retemp){
sendTemp(HeurDebut,HeurFin,jour,Njour);
retemp = false;
}
form.style.display ="block";
});
}
解决方案
推荐阅读
- ios - iOS 中的 Alamofire 正在接收字典而不是数组
- python - 根据具有相邻索引的不同列中的多行编辑熊猫数据框的列
- javascript - 计算指定列表中关键字出现的频率
- java - Spotify:在活动之间传递 SpotifyAppRemote
- c# - c#TextBoxFor 助手在帖子上没有正确绑定
- ms-access - 数据库已被机器 'XXX' 上的用户 'XXX' 置于状态
- oracle - 如何在 where 子句中使用 Max
- ios - 有什么方法可以禁用 UITextField 中占位符文本的可访问性画外音?
- react-native - 如何在反应中处理调度后导航
- node.js - 如何让 gulp-better-sass-inheritance 编译所有文件