【问题标题】:Converting 'touchstart' event to 'mousedown' event将“touchstart”事件转换为“mousedown”事件
【发布时间】:2015-12-27 21:23:33
【问题描述】:

我收到客户的一项请求,要求更改 HTML 包以支持桌面浏览器。最初,该软件包被开发为仅支持 ipad。所以这个包的开发充满了'touchstart'事件。现在我想将touchstart 转换为mousedowntouchstart mousedown。示例代码供您参考。这在 iPad 上运行良好。但不是在桌面上。

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

我确信查找和替换将花费更多时间,而不是有效的时间。是否有任何解决方案或查找和替换是唯一的解决方案。提前致谢。

【问题讨论】:

  • 没有任何代码我们帮不了你。

标签: javascript jquery html


【解决方案1】:

在 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');
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    相关资源
    最近更新 更多