简体   繁体   中英

Event Touch the JavaScript button

good afternoon I created button to start the rotation of a motor in an ESP8266 when tight it turns when released it stops to turn. My problem is that it does not work for the cell phone because they use the Touth function instead of the mouse function. I would like the help of you, because I could not implement the touth function in the button I searched in several places but I did not find a solution.

<input type="button" onmousedown="Horario()" value="horario" class="event" onmouseup="Stop()">


<input type="button" onmousedown="AntHorario()" value="Anthorario" onmouseup="Stop()">


function Horario() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://192.168.137.55/horario=1");
xmlhttp.send();
}
function AntHorario() {

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://192.168.137.55/anthorario=1");
xmlhttp.send();
}
function Stop() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://192.168.137.55/stop=1");
xmlhttp.send();
}

Looks like all you need is to add the touch events ( ontouchstart and ontouchend attributes):

<input type="button" onmousedown="Horario()" value="horario" class="event" onmouseup="Stop()" ontouchstart="Horario()" ontouchend="Stop()">
<input type="button" onmousedown="AntHorario()" value="Anthorario" onmouseup="Stop()" ontouchstart="AntHorario()" ontouchend="Stop()">

You can read more about touch events here: Javascript touch events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM