plain javascript, onclick not working on mobile

后端 未结 3 1238
失恋的感觉
失恋的感觉 2021-01-24 03:47

Now I am not a star really with Javascript, but i seem to encounter the all known problem with mobile devices and the onclick function. Onclick requires a mouse action where off

3条回答
  •  梦毁少年i
    2021-01-24 04:14

    Try to change onclick to addEventListener and see if that helps you..

    // When the user clicks the button, open the modal 
    btn.addEventListener('click', function () {
        var x = window.innerWidth;
        if (x > 768) {
            //event.preventDefault();
            modal.style.display = "block";
        } else {
            //event.preventDefault();
        }
    });

    You can also pass named function to addEventListener

提交回复
热议问题