비슷한 질문을했지만 실제 만족할만한 대답을 얻지 못했기 때문에 여기서 다시 시도 할 것입니다. 나는 다음과 같은 코드를 사용하는 경우 :e.preventDefault()가 방탄하지 않습니까?
$("#element") .on('click', function() {
// do something
})
.on('touchstart', function(e) {
e.preventDefault();
// do the same thing but on touch device like iPad f.e.
// and more over PLEASE do not fire the click event also!
});
을 나는 해고하지 않았다 클릭 이벤트가 (때문에 브라우저가 이벤트를 통해 작동합니다있는 계층의) 결코 것을 기대하고 있지만, 사실 난의 말을 할 수있는 요소를 터치하면 클릭 이벤트가 한 번 발생하는 것보다 20 번. 왜?
그리고 나는 또한 같은 것들을 시도 : 조금 더 단단한하지만 방탄 것 같았다
$("#element") .on('click', function() {
// do something
})
.on('touchstart', function(e) {
e.preventDefault();
e.stopPropagation();
// do the same thing but on touch device like iPad f.e.
// and more over PLEASE do not fire the click event also!
return false;
});
합니다. 작동하는 것 같다하지만, 지독하게 바보
$("#element") .on('click', function() {
if (!touchdevice) {
// do something
};
})
.on('touchstart', function(e) {
e.preventDefault();
e.stopPropagation();
// do the same thing but on touch device like iPad f.e.
// and more over PLEASE do not fire the click event also!
return false;
});
, 그것은되지 않습니다 : 그래서 내가해야 할 일을했을? 아이디어가있는 사람은 누구입니까? 감사!
편집 :
var touched;
$("#element") .on('click', function() {
if (!touched) {
// do something
};
})
.on('touchstart', function(e) {
e.preventDefault(); // actual senseless here
e.stopPropagation(); // actual senseless here
touched = true;
// do the same thing but on touch device like iPad f.e.
// and more over PLEASE do not fire the click event also!
return false; // actual senseless here
});
이들 어서 : 그래서 난 정말 그런 짓을했다! 클릭 이벤트가 터치 감각적 인 브라우저와 일반 브라우저 (또는 새롭게 결합 된 브라우저)를 모두 처리 할 수 있도록 두 번 실행되지 않도록 동일한 요소에서 터치 시작 및 클릭 이벤트를 사용하는 것이 안전하고 일반적인 방법이어야합니다. 어떻게 할 건데?
이 문제는 http://stackoverflow.com/questions/27225577/how-to-prevent-ghost-clicks-on-hyperlinks-when-tapping-on-touch-device와 관련이있을 수 있습니다. 요소의 바깥 쪽을 탭하면 "클릭"이 발생합니다. – aKzenT
귀하의 의견을 보내 주셔서 감사합니다! 지금까지 내가하고있는 것을보기 위해 내 자신의 대답을보십시오. – Garavani