reactnative js onclick 模拟单击/双击事件
reactnative中没有双击事件,只能通过setTimeout实现
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <button id='btn'>click me</button> </body> <script> var id=document.getElementById('btn'); var lastclick; var timer; id.onclick = ()=>{ const clickTime = new Date().getTime(); if(lastclick && (clickTime-lastclick<300)){ //第二次及以上点击 clearTimeout(timer); console.log('dblclick'); }else{ //第一次点击 timer = setTimeout(()=>{ console.log('click'); },300); } lastclick = clickTime; } </script> </html>