demo.html
1005 Bytes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
</head>
<body>
<button id="b1">b1</button>
<button id="b2">b2</button>
<script type="text/javascript">
document.querySelector('#b1').addEventListener('touchstart', function() {
console.log(1)
})
document.querySelector('#b2').addEventListener('touchstart', function() {
console.log(2)
})
setTimeout(function() {
var evt = document.createEvent('UIEvent');
evt.initUIEvent('touchstart', true, true);
var target1 = document.querySelector("#b1");
target1.dispatchEvent(evt);
var target2 = document.querySelector("#b2");
target2.dispatchEvent(evt);
target2.dispatchEvent(evt);
}, 2000)
</script>
</body>
</html>