首页 > 如何模拟触发touchstart

如何模拟触发touchstart

如题,我想要在进入页面的时候,模拟触发input标签的touchstart事件,我应该如何做?


window.onload = function () { 

     var bot = document.getElementById('bot');
     bot.addEventListener('touchstart', function () { alert('touchstart'); }); 
     creatTouchstartEventAndDispatch(bot); 

     function creatTouchstartEventAndDispatch (el) { 
          var event = document.createEvent('Events');
          event.initEvent('touchstart', true, true); 
          el.dispatchEvent(event); 
     } 

}

上述回答为oschina上的朋友cirplan提供

【热门文章】
【热门文章】