6
나는 phonegap을 사용하여 Android 앱을 제작하고 있습니다.JS를 사용하여 phonegap으로 사용자 접촉을 감지하는 방법
사용자로부터 터치 이벤트를 감지하여 알림을 팝업 할 수 있습니다. 그러나 자바 스크립트에서 ontouch 이벤트를 호출하려면 어떻게해야합니까?
감사합니다.
나는 phonegap을 사용하여 Android 앱을 제작하고 있습니다.JS를 사용하여 phonegap으로 사용자 접촉을 감지하는 방법
사용자로부터 터치 이벤트를 감지하여 알림을 팝업 할 수 있습니다. 그러나 자바 스크립트에서 ontouch 이벤트를 호출하려면 어떻게해야합니까?
감사합니다.
다음은 touchstart
및 touchend
을 보여주는 예입니다. 터치 이벤트를 첨부하는 두 가지 방법 : 요소 속성 또는 JavaScript addEventListener
을 보여줍니다.
터치 이벤트를 수신 중이므로 마우스 이벤트를 지원하는 데스크톱 브라우저에서 이벤트가 실행되지 않습니다. 페이지를 테스트하려면 Android 또는 iOS 시뮬레이터를 열 수 있습니다.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0;" />
<style type="text/css">
a {
color:black;
display:block;
margin:10px 0px;
}
</style>
<script type="text/javascript">
function onload() {
document.getElementById('touchstart').addEventListener('touchstart', hello, false);
document.getElementById('touchend').addEventListener('touchend', bye, false);
}
function hello() {
alert('hello');
}
function bye() {
alert('bye');
}
</script>
<title>Touch Example</title>
</head>
<body onload="onload();">
<h1>Touch</h1>
<a href="#" ontouchstart="hello();return false;">Attribute: ontouchstart</a>
<a href="#" ontouchend="bye();return false;">Attribute: ontouchend</a>
<a href="#" id="touchstart">addEventListener: touchstart</a>
<a href="#" id="touchend">addEventListener: touchend</a>
</body>
</html>
좋아, 내가 감사에게 .. 내가 밖으로 시도 – Dayzza
@mwbrroks을 다할 것입니다 그것은 링크/버튼과 함께 사용하기에 적합합니다. 그러나 그것이 어떤 링크 또는 버튼도없이 빈 화면에서 작동 할 수 있는지 궁금 해서요. 긴 사용자가 화면 어디서나 그것이 팝업을 표시합니다 터치 의미. 가능한가요? :) thanks – Dayzza
Do a window.addEventListener (etc) – Harry