首页 > 解决方案 > 如何使用鼠标事件等触摸事件在移动设备中选择元素

问题描述

我有代码前时间表,用于选择当天的元素,它在带有鼠标事件的笔记本电脑设备中工作,但在移动设备中的触摸事件中不起作用,我有另一个问题图标,用于在桌面设备工作中关闭表单 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";
});
}

标签: javascripthtml

解决方案


推荐阅读