可以在 onload 后,先用 createEvent 創(chuàng)建模擬事件,再用 dispatchEvent 觸發(fā)就可以了
<script>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);
}
}</script>