简体   繁体   English

将“touchstart”事件转换为“mousedown”事件

[英]Converting 'touchstart' event to 'mousedown' event

I got one request from my client to change the HTML package to support Desktop browsers.我收到客户的一项请求,要求更改 HTML 包以支持桌面浏览器。 Initially that package was developed to support only the ipads.最初开发该软件包仅支持 ipad。 So the package was developed with full of 'touchstart' event.所以这个包是在充满“touchstart”事件的情况下开发的。 now I want to convert the touchstart into mousedown or touchstart mousedown .现在我想将touchstart转换为mousedowntouchstart mousedown sample code for your reference.示例代码供您参考。 This is working fine in iPads.这在 iPad 中运行良好。 But not in desktop.但不是在桌面。

 $('.toggle-button').bind("touchstart",function() {
   alert("toggle button tapped");
 });

I am sure find and replace will take more time and not the effective one.我确信查找和替换需要更多时间,而不是有效的时间。 Is there any solution for this or find and replace is the only solution.是否有任何解决方案或查找和替换是唯一的解决方案。 Thanks in advance.提前致谢。

trigger the mousedown event ,inside touchstart event.在 touchstart 事件中触发 mousedown 事件。

var elem = document.getElementById('yourdiv');
 $('body').on('touchstart', '[id^="showmenu_"]', function(e){
        e.preventDefault();
       elem.dispatchEvent(new Event('mousedown'))
    });
$(elem).on('mousedown', function () {
    alert('on');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM